I’m sorry if i offended you guys in any way. I actually did work on the code, I am using 2 buttons and 1 servomotor, and here it is (I made 2):
First:
int button1 = 1;
int button2 = 2;
Servo myservo;
int pos = 0; // variable to store the servo position
void setup() {
pinMode(button1, INPUT);
pinMode(button2, INPUT);
myservo.attach(13);
}
void loop() {
digitalRead(button1);
for (pos = 0; pos <= 90; pos += 1) {
myservo.write(pos);
delay(15000);
}
for (pos = 90; pos >= 180; pos -= 1) {
myservo.write(pos);
delay(15000);
}
{ digitalRead(button2)
for (pos = 0; pos <= 90; pos += 1) {
myservo.write(pos);
delay(15000);
}
for (pos = 90; pos >= 180; pos -= 1) {
myservo.write(pos);
delay(15000);
Second:
// pushbutton pin
const int buttonPin = 0;
// servo pin
const int servoPin = 1;
Servo servo;
//create a variable to store a counter and set it to 0
int counter = 0;
void setup()
{
servo.attach (servoPin);
// Set up the pushbutton pins to be an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
// local variable to hold the pushbutton states
int buttonState;
//read the digital state of buttonPin with digitalRead() function and store the //value in buttonState variable
buttonState = digitalRead(buttonPin);
//if the button is pressed increment counter and wait a tiny bit to give us some //time to release the button
if (buttonState == LOW) // light the LED
{
counter++;
delay(150);
}
if(counter == 0)
servo.write (20); // zero degrees
else if(counter == 1)
servo.write(90);
else if(counter == 2)
servo.write (150);
else if(counter == 3)
servo.write (180);
//else reset the counter to 0 which resets thr servo to 0 degrees
else
counter = 0;
}