Skip to content

Instantly share code, notes, and snippets.

@Simsso
Last active April 5, 2020 07:57
Show Gist options
  • Select an option

  • Save Simsso/bf4386e3229e9f0bccd38b981076eea9 to your computer and use it in GitHub Desktop.

Select an option

Save Simsso/bf4386e3229e9f0bccd38b981076eea9 to your computer and use it in GitHub Desktop.
Arduino sketch boilerplate
// 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