void setup() { pinMode(9, OUTPUT); // LED on pin 9 pinMode(8, OUTPUT); // virtual ground for LED digitalWrite (8, LOW); // virtual ground for LED}void loop() { digitalWrite ( 9, (millis()%500 < 250) ? 1 : 0 ); // flash LED at 2Hz // code that runs all the time goes here}
The single line of code in the loop below flashes a LED without use of delay().Only issue I see is that pin 9 is being written to on every loop cycle. Is this a bad thing to be doing ?
OK. I understand. No practical limit on reading or writing with SRAM.I'm still weak on understanding differnce in purpose of Flash vs EEPROM.Both non-volatile. Bootloader and sketch stored in Flash.What's EEPROM for then ? Why couldn't non-volatile data be stored in flash ? Why two kinds of non-volatile memory ?
Is this a bad thing to be doing ?
- Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
digitalWrite ( 9, ((millis() & 0x1FF) < 255) ? 1 : 0 ); // flash LED at 2Hz
The reason I was interested in a simpler way to flash the LED was just to avoid having to deal with the logic and curly brackets that go with a *proper* "blink without delay".
#include "Timer.h" // LED LED_BUILTINTimer t;void setup(){ pinMode(LED, OUTPUT); t.oscillate(LED, 1000, LOW);}void loop(){ t.update();}