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. If you want to know when more are added make sure you subscribe to the RSS feed or email notification list.
Baldengineer’s Arduino millis() Examples
- Arduino Multitasking – Step by step examples of how to convert delay() code into millis() based code, to simulate multitasking.
- Police Lights – Flash two LEDs like strobing police lights
- Control ON and OFF time for a flashing LED. – More control than “blink without delay”
- Stopwatch Example – Calculate how much time code takes to execute
- Chasing LEDs – Larson-scanner style chasing pattern
- De-bounch a button (or switch) – No need for de-bouncing capacitor
- Delayed events after a button push – Timed events (button push is just example.)
- analogWrite() PWM Fading – No delay() and a simple function to keep a LED fading with PWM
- 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.