Hello all, very new to Arduino here.
Here I have a simple serial program which is intended to display "the lights are off" when 0 is input into the serial monitor, and "the lights are on" when 1 is input. However, the program simply jumps to the else case when i run this. No matter how much I tweak it.
My only guess is that it's something to do with bytes and the type of input the Serial Monitor accepts???
Code listed below. If you find any errors, I'd appreciate it enormously if you'd also go to the liberty to describe why the correct statement(s) needs to be implemented.
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
while(Serial.available() > 0){
int lightControl = Serial.read();
if(lightControl == 0)
{
digitalWrite(13, LOW);
Serial.println("Light is off fam");
}
else if(lightControl == 1)
{
digitalWrite(13, HIGH);
Serial.println("THE LIGHTS ARE ON ");
}
else
{
Serial.println("stop writing random numbers pls");
}
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.