Scenaio
Mechanism
Arduino testing
Code:
#include <Servo.h>
Servo myservo;
boolean switchValue1;
boolean switchValue2;
boolean switchValue3;
void setup() {
pinMode(3, INPUT);
pinMode(5, INPUT);
pinMode(7, INPUT);
myservo.attach(9);
}
void loop() {
switchValue1 = digitalRead(3);
switchValue2 = digitalRead(5);
switchValue3 = digitalRead(7);
if(switchValue1==LOW && switchValue2==LOW && switchValue3==LOW) {
myservo.write(0);
}
else if(switchValue1==HIGH && switchValue2==LOW && switchValue3==LOW) {
myservo.write(60);
}
else if(switchValue1==HIGH && switchValue2==HIGH && switchValue3==LOW) {
myservo.write(120);
}
else if(switchValue1==HIGH && switchValue2==HIGH && switchValue3==HIGH) {
myservo.write(179);
}
}
No comments:
Post a Comment