Dear Reader,
i am building a tabletennis maschine and i am coded a programm which should when i press a button on my phone make a servo motor move in 3 different positions all 1,5 seconds. This works perfectly. but then when i press another button then the code is still running from the first button! ![]()
#include <Servo.h>
Servo motor;
int signal= 0;
void setup() {
motor.attach(9);
motor.write(45);
Serial.begin(9600); //CONNECTION RATE FÜR BT MODUL
}
void loop() {
if(Serial.available() > 0){
signal = Serial.read();
if(signal == '1'){
while(signal=='1'){
for(int position=45;position<=135; position+=45){
motor.write(position);
delay(1500);
}
for(int position=135;position>=45; position-=45){
motor.write(position);
delay(1500);
}
}
if(signal == '2')motor.write(45);
if(signal == '3')motor.write(90);
if(signal == '4')motor.write(135);
}
}
}