Having tried everything I could find or think of I'm hoping someone might be able to point me in the
right direction to set up some loops. Nothing I'm trying will work or compile.
Just trying to have sections of my test sketch loop when serial characters
are received, i.e. "a", "b" etc.
Here's what I have so far, without the loops of course.
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the sensor:
if (Serial.available() > 0) {
char inByte = Serial.read();
Serial.print("Command Received ");
Serial.print(inByte);
Serial.print("\n\r");
switch (inByte) {
case 'a':
//while(Serial.available() == 0) // while there are no new characters...
{
digitalWrite(13, HIGH); // set the LED on
delay(500); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(500); // wait for a second
}
break;
case 'b':
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
break;
case 'c':
digitalWrite(13, HIGH); // set the LED on
delay(1500); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1500); // wait for a second
break;
case 'd':
digitalWrite(13, HIGH); // set the LED on
delay(2000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(2000); // wait for a second
break;
default:
// turn all the LEDs off:
for (int thisPin = 13; thisPin < 13; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
}
}
Goal is to have each section loop indefinitely till another serial command is received.
Really appreciate any pointers on this!
Thanks,
Carl