I am doing a project with bluetooth and an LED. I wrote a code which supposed to turn on an LED after it receives a byte of value 1 after 5 seconds, unless it receive another byte of value 1 (which make it need to wait another 5 seconds) so that if it receive the byte periodically, the LED doesnt turn on, and only turn on if byte value sending is stopped/bluetooth disconnected. I wrote this code and it doesn't seem to work. It doesn't even turn on the LED after 5 seconds. Can you help me spot the mistake here?
unsigned long timebetween=5000;
unsigned long lastreceivedtime;
int value;
bool timerReady = false;
void setup() {
pinMode (11,OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
if( Serial.available() >0){
value = Serial.read();
}
if ( value ==1 ){
lastreceivedtime = currentMillis;
timerReady = true;
}
if(timerReady) {
if((unsigned long)(currentMillis - lastreceivedtime) >= timebetween){
digitalWrite(11, HIGH);
delay(90);
}
}
}
Serial.read()
returns?