Arduino Millis() Examples

Example code using millis()

You’ve recently learned about millis() and can’t way to delete all of your references to delay().  The problem is that you don’t know quite how to convert your code into millis()-compatible code.  Here is a (running) list of millis() examples I’ve put together to help.

Baldengineer’s Arduino millis() Examples

  1. Arduino Multitasking - Step by step examples of how to convert delay() code into millis() based code, to simulate multitasking.
  2. Police Lights - Flash two LEDs like strobing police lights
  3. Control ON and OFF time for a flashing LED. - More control than “blink without delay”
  4. Stopwatch Example - Calculate how much time code takes to execute
  5. Chasing LEDs - Larson-scanner style chasing pattern
  6. De-bounch a button (or switch) - No need for de-bouncing capacitor
  7. Delayed events after a button push - Timed events (button push is just example.)
  8. analogWrite() PWM Fading - No delay() and a simple function to keep a LED fading with PWM
  9. Detect Short and Long Button Press - Give one button multiple functions

You might also want to check out my “Blink Without Delay - Line by Line  Tutorial.” It is a much more in-depth explanation than the comments provided with the Arduino IDE example.