I'm new to the forums, so I apologize ahead of time for any errors I commit. My ultimate goal is to write a sketch that lights three LEDs in a cascading manner. Its quite simple, and I have gotten it to work by itself. The problem comes when I try to incorporate a pseudo "Off switch" into the program. I attempt to assign a value to the variable READ through the serial monitor(SM) . This value is then evaluated to be true or false in an if..else if.. structure. If the first if statement is true, it executes the cascade. If the else if statement returns true, it executes "pseudo off". If neither are true it asks to input a value of 1 or 2.
The program below compiles and is uploaded without error, but when I attempt to interact with the program via SM nothing happens. In addition I have been unable to get Serial.print("Random String") to print to the SM. I am using an Arduino Uno with IDE 1.01. I'm guessing I have a fundamental misunderstanding of something below but I can't seem to catch my mistake. Thanks for the help.
Below is the code discussed above:
int const ledpin4 = 4;
int const ledpin5 = 5;
int const ledpin6 = 6;
int Read = 0;
void setup()
{
pinMode(ledpin4,OUTPUT);
pinMode(ledpin5,OUTPUT);
pinMode(ledpin6,OUTPUT);
} //END void setup()
void loop()
{
Serial.print("Enter 1 for LED Cascade or 2 for off.");
Read = Serial.read();
if(Read==1)
{
Serial.print("LED Cascade");
for(int ledpin = 4; ledpin <7; ledpin++)
{
digitalWrite(ledpin,HIGH);
delay(100); // 100ms
digitalWrite(ledpin,LOW);
} //END for()
} //END if()
else if(Read==2)
{
Serial.print("LED's Off");
for(int ledpin = 4; ledpin <7; ledpin++)
{
digitalWrite(ledpin,LOW);
} //End else for()
} //END else if()
else
Serial.print("Invalid Entry: Enter 1 or 2");
} //END void loop()
Thank you very much Magician. I played around with Serial.available() a little bit with a switch case, but I haven't looked into it with any detail. I'll work on it and post the updated code if I make progress.