Advertisement
oxguy3

pointless machine

Jan 9th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myServo; // create servo object to control a servo
  4.  
  5. const int switchPin = 2; // the number of the switch pin
  6. const int servoPin = 11; // the number of the servo pin
  7. const int ledPin = 13; // the number of the LED pin
  8.  
  9. int switchState = 0; // variable for reading the switch status
  10.  
  11.  
  12. void setup() {
  13. // initialize the LED pin as an output
  14. pinMode(ledPin, OUTPUT);
  15.  
  16. // initialize the switch pin as an input
  17. pinMode(switchPin, INPUT);
  18.  
  19. // attach the servo object to the servo pin
  20. myServo.attach(servoPin);
  21. }
  22.  
  23.  
  24. void loop(){
  25. // get the state of the switch
  26. switchState = digitalRead(switchPin);
  27.  
  28.  
  29. if (switchState == HIGH) { // if the switch is on
  30.  
  31. // turn on the LED
  32. digitalWrite(ledPin, HIGH);
  33.  
  34. // wait half a second
  35. delay(300);
  36.  
  37. // push the servo arm out
  38. myServo.write(0);
  39.  
  40. } else { // if the switch is off
  41.  
  42. // turn off the LED
  43. digitalWrite(ledPin, LOW);
  44.  
  45. // pull the servo arm in
  46. myServo.write(180);
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement