Daire Byrne
New Member
My name is Max. My world is fire and blood.
Posts: 24
|
Post by Daire Byrne on Apr 18, 2015 17:57:37 GMT
This is the place for people in our group to leave code that will be useful for the Servo, LCD or lights.
|
|
Daire Byrne
New Member
My name is Max. My world is fire and blood.
Posts: 24
|
Post by Daire Byrne on Apr 18, 2015 18:20:43 GMT
the following is just some code for the interactions between the distance sensor in the hoop and the LED in the hoop. This is vital as it records the score. This code is flawed so feel free to work on it.
Int hoop = 0.05 Int sensor = 6 Int lights1 = 9
Void setup () { pinMode (sensor, INPUT) pinMode (lights1, OUTPUT) Serial.begin(9600) }
Void loop () { analogRead (hoop) If hoop < 0.05; { digitalWrite(lights1, HIGH) Delay (2000) } Else digitalWrite (lights1, LOW) }
|
|
breno
New Member
Posts: 1
|
Post by breno on Apr 24, 2015 18:32:47 GMT
I gave Adam the led code so I don't have it anymore
|
|
Daire Byrne
New Member
My name is Max. My world is fire and blood.
Posts: 24
|
Post by Daire Byrne on Apr 25, 2015 20:03:53 GMT
This code is for the combination of the distance IR sensor and the light on the hoop indicating that the basket has been scored.
int hoop = 6 int lights1 = 9
void setup() { pinMode (hoop, INPUT); pinMode (lights1, OUTPUT); Serial.begin(9600); }
void loop() { int hoop_val=analogRead(hoop); if (hoop_val < 5); { digitalWrite(lights1, HIGH); delay(2000); } else { digitalWrite(lights1, LOW); } }
|
|
Daire Byrne
New Member
My name is Max. My world is fire and blood.
Posts: 24
|
Post by Daire Byrne on Apr 25, 2015 20:19:10 GMT
And here is some preliminary code for the Servo attached by the band to the spoon to coil back slowly, wait for the (currently seperate) trigger to be used by the player and then return to a lax state after 15 seconds.
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup() { myservo.attach(9); }
void loop() { for(pos = 0; pos < 180; pos += 1); { myservo.write (pos); delay (10); } delay(15000); for(pos = 180; pos >=1; pos -= 180); { myservo.write(pos); delay(1500); } }
|
|
Daire Byrne
New Member
My name is Max. My world is fire and blood.
Posts: 24
|
Post by Daire Byrne on May 3, 2015 16:31:48 GMT
Here is some code for the hoop's distance sensor combined with the code for the LED array that will run if a basket is achieved.
int hoop = 6; int lights1 = 9; int led1 = 3; int led2 = 5; int led3 = 11;
void setup() { pinMode(hoop, INPUT); pinMode(lights1, OUTPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); Serial.begin(9600); }
void loop() { int hoop_val=analogRead(hoop); if (hoop_val < 5) { digitalWrite(lights1, HIGH); delay(2000); { digitalWrite(led1, HIGH); delay(3000); digitalWrite(led1, LOW); delay(3000); } delay(1000); { digitalWrite(led2, HIGH); delay(3000); digitalWrite(led2, LOW); delay(3000); } delay(1000); { digitalWrite(led3, HIGH); delay(3000); digitalWrite(led3, LOW); delay(3000); } } else; { digitalWrite(lights1, LOW); } }
|
|
Daire Byrne
New Member
My name is Max. My world is fire and blood.
Posts: 24
|
Post by Daire Byrne on May 19, 2015 21:05:50 GMT
Here is some crude code that unites the entire system. It is (almost certainly) wrong, but it is a starting point at least.
#include <Servo.h>
Servo myservo;
int timeTaken = millis(); int start = millis(); int button = 3; int motor1 = 5; int motor2 = 6; int switch1 = 9; int pos = 0;
void setup() { pinMode(button, INPUT); //this is the button that the player will press after moving the catapult to a satisfactory position pinMode(motor1, OUTPUT); //these two dictate the actions of the motor pinMode(motor2, OUTPUT); pinMode(switch1, INPUT); pinMode(10,OUTPUT); //this code is specific to the LEDs on the hoop pinMode(A0,INPUT); //this refers to the distance sensor digitalWrite(10,LOW); Serial.begin(9600); myservo.attach(11); //this includes the Servo that will operate the latching system }
void loop() { if(digitalRead(button)==1); { int start = millis(); digitalWrite(motor1, HIGH); digitalWrite(motor2, LOW); delay(start); } while((switch1)==0); { int timeTaken= millis()-start; digitalWrite(motor1, HIGH); digitalWrite(motor2, LOW); delay(timeTaken); } //this code runs the uncoiling of the twine and the latching and unlatching of the Servo { if((switch1)==1); for(pos <= 90; pos += 90;) myservo.write(pos); delay(2000); digitalWrite(motor1, LOW); digitalWrite(motor2, HIGH); delay(timeTaken); for(pos >=90; pos-=90;) myservo.write(pos); } //this code governs the sensor and lights on the hoop's backboard { int a=analogRead(A0); if(a<600) { digitalWrite(10,HIGH); } else; { digitalWrite(10,LOW); } Serial.println(a); } }
|
|