Mastering Arduino millis() Function for Non-Blocking Code

Added:

Millis Basics
Timeline View
Once-Off Events
Repetitive Loop
Coding Pattern
Logic Walkthrough
Review & Recap

Millis Basics

0:11
Playing Section
  • 1

    Millis tracks milliseconds since power-up, starting at zero.

  • 2

    It counts to 4 billion then overflows after 49 days.

  • 3

    The function runs automatically in the background using a timer.

Basic Arduino programming structure, including the distinction between the setup() and loop() functions.
The behavior and limitations of the blocking delay() function in microcontroller environments.
Fundamental variable data types, specifically understanding why 'unsigned long' is necessary for tracking time in milliseconds.
Basic control flow and conditional logic, particularly using 'if' statements to evaluate time differences.
Designing Finite State Machines (FSM) to manage complex, multi-tasking behavior without blocking code execution.
Applying non-blocking timing techniques to software debouncing for physical buttons and sensors.
Understanding hardware interrupts (using attachInterrupt) for immediate, hardware-level event handling.
Transitioning to Cooperative Multitasking and Real-Time Operating Systems (RTOS) for advanced embedded applications.
254.3K views6.3Klikes14:26@programmingelectronicsOriginal Release: 2019-04-18

The millis() function in Arduino returns the number of milliseconds since the board was powered on, enabling non-blocking timed events by comparing current time against a stored previous time value; to create repetitive timed events, calculate the time difference between current and previous times, and when this difference exceeds the desired interval, execute the event code and update the previous time to current time, allowing the program to perform other tasks during the waiting period.