Tutorial by Examples

One of the most straight forward way of making an LED blink is: turn it on, wait a bit, turn it off, wait again, and repeat endlessly: // set constants for blinking the built-in LED at 1 Hz #define OUTPIN LED_BUILTIN #define PERIOD 500 void setup() { pinMode(OUTPIN, OUTPUT); // sets t...
The elapsedMillis library provides a class with the same name that keeps track of the time that passed since it was created or set to a certain value: #include <elapsedMillis.h> #define OUTPIN LED_BUILTIN #define PERIOD 500 elapsedMillis ledTime; bool ledState = false; void setup...
This is very close to an example from the arduino docs: // set constants for blinking the built-in LED at 1 Hz #define OUTPIN LED_BUILTIN #define PERIOD 500 // this is in milliseconds int ledState = LOW; // millis() returns an unsigned long so we'll use that to keep track of time unsigned...
#include <elapsedMillis.h> void setup() { Serial.begin(115200); elapsedMillis msTimer; elapsedMicros usTimer; long int dt = 500; delay(dt); long int us = usTimer; long int ms = msTimer; Serial.print("delay(");Serial.print(dt);Serial.println(") to...
If you have more than 1 task to execute repeatedly in different intervals, use this example as a starting point: unsigned long intervals[] = {250,2000}; //this defines the interval for each task in milliseconds unsigned long last[] = {0,0}; //this records the last executed time for each ...

Page 1 of 1