const int DriverA_1 = 6; const int DriverA_2 = 7; const int DriverB_1 = 8; const int DriverB_2 = 9; char key; char S = 's'; char C = 'c'; void setup() { pinMode(DriverA_1, OUTPUT); pinMode(DriverA_2, OUTPUT); pinMode(DriverB_1, OUTPUT); pinMode(DriverB_2, OUTPUT); Serial.begin(115200); } void loop() { if (Serial.available()) { key = Serial.read(); if(key == S){ Serial.print("Start!"); Serial.println(""); motor(HIGH, LOW, 3000); } else if(key == C){ Serial.print("Stop!"); Serial.println(""); motor(LOW, LOW, 3000); } } } void motor(int a1, int a2, int d){ digitalWrite(DriverA_1, a1); digitalWrite(DriverA_2, a2); digitalWrite(DriverB_1, a1); digitalWrite(DriverB_2, a2); delay(d); }