/*************************************************************** /*Servo_Button written by Russell Winkler for Things That Think /*at University of Colorado, Boulder. Spring 2011 /***************************************************************/ #include Servo myservo; // create servo object to control a servo const int buttonPin = A0; // create a button that listens on the AO input pin int pos = 0; // variable to store the servo position int rotations = 2.5; // variable that determines the number of rotations (1 = 360 degrees) int buttonState = 0; // variable used to store the current button state (on or off) void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo.write(85); // using a continuous servo 90 is full stop pinMode(buttonPin, INPUT); // set the button as an input Serial.begin(9600); //Outputs any serial communications } //Main loop that listens for the press of the button and scrolls the paper accordingly void loop() { buttonState = digitalRead(buttonPin); // reads the button input if(buttonState == HIGH) { // if the button is on myservo.write(100); // makes the servo rotate slowly in a counterclockwise direction delay(1150 * rotations); // for the set amount of milliseconds myservo.write(90); // stops the servo } else { myservo.write(85); // if the button is off, stop the servo. } }