void loop() { unsigned long now = millis(); // time since boot in milliseconds if(Serial.available()) { level = Serial.read() % 4; last_message = now; } else if(now - last_message > 60*1000 && level < 3) { // if no message received after 60*1000 ms, increase alert level last_message = now; // well, sorta level ++; } if(level != oldlevel) { set_led_color(level); oldlevel = level; } delay(50); }
Hint: sizeof(int) == 2 on avr
Entry first conceived on 13 March 2009, 1:33 UTC, last modified on 15 January 2012, 3:46 UTC
Website Copyright © 2004-2024 Jeff Epler