GMU:Sensor Hacklab/Rachel Smith/Link to Arduino code: Difference between revisions

From Medien Wiki
(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...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<nowiki>//servo library
<nowiki>//servo library


#include <Servo.h>
#include <Servo.h>


 
</nowiki>
char val;
char val;


Line 11: Line 12:


Servo myservo3;
Servo myservo3;




void setup() {
void setup() {


myservo1.attach(9);
myservo1.attach(9);
Line 28: Line 29:


}
}


void loop() {
void loop() {
if(Serial.available()) {
if(Serial.available()) {
//read values from processing
//read values from processing
Line 74: Line 73:
}
}
delay(10);
delay(10);
}</nowiki>
}

Latest revision as of 12:56, 10 June 2016

//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); }