Last active
April 5, 2020 07:57
-
-
Save Simsso/bf4386e3229e9f0bccd38b981076eea9 to your computer and use it in GitHub Desktop.
Arduino sketch boilerplate
This file contains hidden or 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
| // library imports | |
| #define SERIAL_DEBUG | |
| // global variables | |
| void setup() { | |
| #ifdef SERIAL_DEBUG | |
| Serial.begin(9600); | |
| Serial.println("Initializing..."); | |
| #endif | |
| pinMode(13, OUTPUT); | |
| // setup | |
| } | |
| void loop() { | |
| #ifdef SERIAL_DEBUG | |
| Serial.println("Running..."); | |
| #endif | |
| // local main event loop variables | |
| uint32_t lastMillis = millis(); | |
| while (true) { | |
| uint32_t currentMillis = millis(); | |
| if (currentMillis < lastMillis) { | |
| // skip main loop in case of millis() overflow | |
| lastMillis = currentMillis; | |
| continue; | |
| } | |
| digitalWrite(13, (currentMillis / 1000) % 2); | |
| // main event loop actions | |
| lastMillis = currentMillis; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment