I am trying to use serial communications to do something as simple as turning on and off LEDs because i have a larger more complex project planned of the future using serial. I am using the following code
int b=4;
int c=5;
int d=6;
int valin=Serial.read();
void setup() {
Serial.begin(9600);
}
void loop() {
switch(valin){
case('b'):{
digitalWrite(b,!digitalRead(b));
Serial.println("LED B Turned On");
}
case('c'):{
digitalWrite(c,!digitalRead(c));
Serial.println("LED C Turned On");
}
case('d'):{
digitalWrite(d,!digitalRead(d));
Serial.println("LED D Turned On");
}
}
}
This code compiles fine but when I send one of the letters through the serial monitor none of the LEDs will light and it prints the "LED turned on" message but for more than one LED so it looks like:
LED B Turned ON
LED C Turned ON
LED D Turned ON
LED C Turned ON
LED D Turned ON