///servo bewegt sich nicht, vgl wokwi 17: pullup
int LEDblau=6;//
int taster=7;//
int tasterstatus = 0;//
int button = 2; //pin of the first button
int button1 = 3; //pin of the second button
#include<Servo.h> //include the servo library
Servo servo; //create a servo object
int pos = 90; //initial position of the servo
void setup() {
pinMode(LEDblau, OUTPUT);//
pinMode(taster, INPUT);//
// put your setup code here, to run once:
servo.attach(9); //pin used by the servo
pinMode(button, INPUT_PULLUP); //define first button as input pullup
pinMode(button1, INPUT_PULLUP); //define second button as input pullup
/*
INPUT_PULLUP send to arduino LOW signal, so, when you press the button, you send a LOW signal to arduino
*/
}
void loop() {
servo.write(pos);
tasterstatus=digitalRead(taster);//
if (tasterstatus == HIGH ) //
{ digitalWrite(LEDblau, HIGH ); //
delay (1000); //
digitalWrite(LEDblau, LOW );
}
else //
{
digitalWrite(LEDblau, LOW) ;//
}
// put your main code here, to run repeatedly:
if (digitalRead(button) == LOW) { //if Value read of the button ==LOW:
pos++; //increases the value of the "pos" variable each time the push button of the left is pressed
delay(5); //5 milliseconds of delay
servo.write(pos); //servo goes to variable pos
}
if (digitalRead(button1) == LOW) { //if Value read of the button ==LOW:
pos--; //decreases the value of the "pos" variable each time the push button of the right is pressed
delay(5); //5 milliseconds of delay
servo.write(pos); //servo goes to variable pos
}
}