wg0z:
wire the switch to a not-currently-used pin and to ground such that the pin is connected to ground when the button is pushed. best to not use pins 0 or 1, or obviously the one in used for the servoput this statement between the for-loops in loop()
while(HIGH == digitalRead(pin_number);put this statement in setup()
pinMode(pin_number, INPUT_PULLUP);
wg0z:
wire the switch to a not-currently-used pin and to ground such that the pin is connected to ground when the button is pushed. best to not use pins 0 or 1, or obviously the one in used for the servoput this statement between the for-loops in loop()
while(HIGH == digitalRead(pin_number);put this statement in setup()
pinMode(pin_number, INPUT_PULLUP);
Thanks for the reply
But I can't seem to get it to work.
I'm using this code with your suggestion:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
void setup() {
pinMode(10, INPUT_PULLUP);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
while(HIGH == digitalRead(10);
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Sketch gives me the following error:
C:\x\x\x\Arduino\sketch_dec30a\sketch_dec30a.ino: In function 'void loop()':
sketch_dec30a:23: error: expected ')' before ';' token
while(HIGH == digitalRead(10);
^
exit status 1
expected ')' before ';' token
What am I doing wrong? :o