char btVal; char lastVal; const int motor_1a = 6; // Motor 1 (Richtung 1) const int motor_1b = 7; // Motor 1 (Richtung 2) const int speed_m1 = 5; // PWM-Port für Geschwindigkeit Motor 1 const int led_1r = 2; const int led_1w = 3; const int led_2r = 8; const int led_2w = 9; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(motor_1a, OUTPUT); pinMode(motor_1b, OUTPUT); pinMode(led_1r, OUTPUT); pinMode(led_1w, OUTPUT); pinMode(led_2r, OUTPUT); pinMode(led_2w, OUTPUT); digitalWrite(led_1w, HIGH); digitalWrite(led_2w, HIGH); } void loop() { // put your main code here, to run repeatedly: if (Serial.available()){ btVal=Serial.read(); } if (btVal=='r' || btVal=='R'){ digitalWrite(motor_1a, HIGH); // Motor 1: Richtung 1 ON digitalWrite(motor_1b, LOW); // Motor 1: Richtung 2 OFF analogWrite(speed_m1, 175); // Motor 1: Geschwindigkeit (0-255) digitalWrite(led_1r, HIGH); digitalWrite(led_2w, HIGH); digitalWrite(led_1w, LOW); digitalWrite(led_2r, LOW); if (lastVal!='r' && lastVal!='R'){ Serial.println("Fahre rückwärts"); lastVal = btVal; } } else if (btVal=='v' || btVal=='V'){ digitalWrite(motor_1a, LOW); // Motor 1: Richtung 1 ON digitalWrite(motor_1b, HIGH); // Motor 1: Richtung 2 OFF analogWrite(speed_m1, 175); // Motor 1: Geschwindigkeit (0-255) digitalWrite(led_1w, HIGH); digitalWrite(led_2r, HIGH); digitalWrite(led_1r, LOW); digitalWrite(led_2w, LOW); if (lastVal!='v' && lastVal!='V'){ Serial.println("Fahre vorwärts"); lastVal = btVal; } } else if (btVal=='0'){ digitalWrite(motor_1a, LOW); // Motor 1: Richtung 1 ON digitalWrite(motor_1b, LOW); // Motor 1: Richtung 2 OFF analogWrite(speed_m1, 0); // Motor 1: Geschwindigkeit (0-255) digitalWrite(led_1w, LOW); digitalWrite(led_2r, HIGH); digitalWrite(led_1r, HIGH); digitalWrite(led_2w, LOW); if (lastVal!='0'){ Serial.println("STOPP"); lastVal = btVal; } } }