Advertisement
djfoo000

Untitled

Jul 14th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. /*
  2. Useless robot sketch
  3. */
  4.  
  5. #include <Servo.h> //include servo library
  6.  
  7. Servo myservo;  //declare servo myservo
  8.  
  9. int x = 0;      //dummy variable for infinite loop
  10. int potPin = A0;    //declare potentiometer pin (analog output pin A0)
  11.  
  12. void setup(){
  13.   myservo.attach(12);    //attach servo to digital pin 12
  14.   myservo.write(180);    //write initial displacement to 180 degs
  15. }
  16.  
  17. void loop(){
  18.  
  19.  while(x<1){
  20.    if(analogRead(potPin) > 150){    //if reading of potentiometer is above treshold
  21.      myservo.write(25);            //move servo arm to 25 deg position
  22.      delay(100);                  //delay 100 milisecond
  23.    }
  24.    else{                      //when reading is below treshold
  25.      myservo.write(180);    //return servo arm to original position
  26.      delay(100);            //delay 100 milisecond
  27.    }
  28.  
  29.  }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement