Last active
December 24, 2019 14:56
-
-
Save nerdralph/8af5ade84839f4cc3256faa470434db8 to your computer and use it in GitHub Desktop.
blink example for MicroCorre using sleep and millis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// blink LED using sleep and millis() on MicroCore | |
// 2019 Ralph Doncaster freeware | |
#define LEDPIN 0 | |
#include <avr/sleep.h> | |
static void sleep_ms(unsigned ms) { | |
ms -= 9; // 1/2 millis minimum increment in MicroCore | |
unsigned snapshot = (unsigned)millis(); | |
// SLEEP_MODE_IDLE is default | |
do { | |
MCUCR = 1 << SE; | |
sleep_cpu(); | |
} while ((((unsigned)millis() - snapshot)) <= ms); | |
} | |
void setup() { | |
pinMode(LEDPIN, OUTPUT); | |
} | |
void loop() { | |
sleep_ms(250); | |
digitalWrite(LEDPIN, HIGH); | |
sleep_ms(750); | |
digitalWrite(LEDPIN, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment