Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- int button1 = 6; //button pin, connect to ground to move servo
- int press1 = 0;
- int button2 = 5; //button pin, connect to ground to move servo
- int press2 = 0;
- Servo servo1;
- Servo servo2;
- int extend = 5; // variable to store and set the servo position
- int lift = 5; // variable to store and set the servo position
- void setup()
- {
- Serial.begin(9600);
- pinMode(button1, INPUT); //out and down
- pinMode(button2, INPUT); //up and in
- servo1.attach(7); //extend servo
- servo2.attach(8); //lift servo
- servo1.write(extend); //starting position
- servo2.write(lift); //starting position
- digitalWrite(6, HIGH); //enable pullups to make pin high
- digitalWrite(5, HIGH); //enable pullups to make pin high
- Serial.println("servo button sweep test 12-23-2013");
- }
- void loop()
- {
- press1 = digitalRead(button1);
- if (press1 == LOW)
- {
- if (extend<175)
- {
- extend=(extend+1);
- if(extend>180) extend=180; //limit upper value
- Serial.println(extend); //for serial monitor debug
- servo1.write(extend); // tell servo to go to position in variable 'extend'
- delay(100); // waits 100ms to slow servo movement
- }
- else
- {
- lift=(lift+1);
- if(lift>180) lift=180; //limit upper value
- Serial.println(lift); //for serial monitor debug
- servo2.write(lift); // tell servo to go to position in variable 'lift'
- delay(100); // waits 100ms to slow servo movement
- }
- }
- press2 = digitalRead(button2);
- if (press2 == LOW)
- {
- if (lift>5)
- {
- lift=(lift-1);
- if(lift<0) lift=0; //limit upper value
- Serial.println(lift); //for serial monitor debug
- servo2.write(lift); // tell servo to go to position in variable 'lift'
- delay(100); // waits 100ms to slow servo movement
- }
- else
- {
- extend=(extend-1);
- if(extend<0) extend=0; //limit upper value
- Serial.println(extend); //for serial monitor debug
- servo1.write(extend); // tell servo to go to position in variable 'extend'
- delay(100); // waits 100ms to slow servo movement
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement