GMU:Sensor Hacklab/Rachel Smith/Link to Arduino code

From Medien Wiki
< GMU:Sensor Hacklab‎ | Rachel Smith
Revision as of 12:51, 10 June 2016 by Rachel (talk | contribs) (Created page with "<nowiki>//servo library #include <Servo.h> char val; Servo myservo1; Servo myservo2; Servo myservo3; void setup() { myservo1.attach(9); myservo2.attach(7); myservo3.a...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

//servo library #include <Servo.h> char val; Servo myservo1; Servo myservo2; Servo myservo3; void setup() { myservo1.attach(9); myservo2.attach(7); myservo3.attach(4); //begin listening to processing Serial.begin(9600); } void loop() { if(Serial.available()) { //read values from processing val = Serial.read(); } //move servo 1 for message 0 received if (val == '0') { myservo2.detach(); myservo3.detach(); myservo1.write(30); delay(2000); myservo1.write(0); delay(2000); myservo2.attach(7); myservo3.attach(4); } //move servo 2 for message 1 received else if (val == '1') { myservo1.detach(); myservo3.detach(); myservo2.write(30); delay(2000); myservo2.write(0); delay(2000); myservo1.attach(9); myservo3.attach(4); } //move servo 3 for message 2 received else if (val == '2'){ myservo1.detach(); myservo2.detach(); myservo3.write(30); delay(2000); myservo3.write(0); delay(2000); myservo1.attach(9); myservo2.attach(7); } delay(10); }