Hello All,
Good Day! ![]()
I am a bit new to Arduino.
What I want to do is activate a loop within the arduino code when a Serial command is activated. I want to control a DC motor with my PC keyboard, and I also want the motors to be controlled with Ping Sensors, but the ping sensor part would only be activated when a particular button lets say 'z' is pressed on my laptop keyboard.
Attached is the code I have so far.
Note:
I haven't added anything concerning the sensors as yet.
const int motor =8;
const int motor2 =9;
const int motor3 =10;
void setup() {
 pinMode(motor, OUTPUT);
 pinMode(motor2, OUTPUT);
 pinMode(motor3, OUTPUT);
 Serial.begin(9600);
 Serial.println("Motor Control");
}
void loop() {
 if (Serial.available() > 0) {
  int data = Serial.read();
  switch(data)
  {
    case 'a' : digitalWrite(motor, HIGH); Serial.print("Vertical Push Down - ON");break ;
case 'b' :Â digitalWrite(motor, LOW); Serial.print("Vertical Push Down - OFF"); break ;
    case 'c' : digitalWrite(motor2, HIGH); Serial.print("Motor One - Activated"); break;
    case 'd' : digitalWrite(motor2, LOW); Serial.print("Motor One - OFF"); break;
    case 'e' : digitalWrite(motor3, HIGH); Serial.print("Motor Two - Activated"); break;
    case 'f' : digitalWrite(motor3, LOW); Serial.print("Motor Two - OFF"); break;
  }
 }
}