FastLED 3.9.15
Loading...
Searching...
No Matches

◆ millis()

fl::u32 fl::millis ( )

Universal millisecond timer - returns milliseconds since system startup.

This function provides consistent timing across all FastLED platforms:

  • Arduino/AVR: Hardware timer-based millis()
  • ESP32/ESP8266: ESP-IDF timing functions
  • ARM: Platform-specific ARM timers
  • WASM: JavaScript-based timing
  • Native/Testing: std::chrono implementation
  • Stub: Fake timer for testing
Returns
Number of milliseconds since the system started
Note
Wraps around approximately every 49.7 days (2^32 milliseconds)
This function is designed to be zero-overhead - it compiles to a direct platform call in optimized builds

Behavior

  • Consistent: All platforms return milliseconds since startup/initialization
  • Monotonic: Time always increases (except on wraparound)
  • Resolution: 1 millisecond resolution on all platforms
  • Wraparound: Consistent wraparound behavior at 2^32 milliseconds

Examples

// Basic timing
fl::u32 start = fl::millis();
do_work();
fl::u32 elapsed = fl::millis() - start;
// Animation timing
static fl::u32 last_frame = 0;
fl::u32 now = fl::millis();
if (now - last_frame >= 16) { // 60 FPS
render_frame();
last_frame = now;
}
// Timeout handling
fl::u32 timeout = fl::millis() + 5000; // 5 second timeout
while (fl::millis() < timeout && !is_complete()) {
process_step();
}
fl::u32 millis()
Universal millisecond timer - returns milliseconds since system startup.
Examples
Animartrix.ino, BeatDetection.ino, FxGfx2Video.ino, and FxNoiseRing.ino.

Definition at line 64 of file chrono.cpp.hpp.

64 {
65#ifdef FASTLED_TESTING
66 // Check for injected time provider first
67 {
68 fl::unique_lock<fl::mutex> lock(get_time_mutex());
69 const auto& provider = get_time_provider();
70 if (provider) {
71 return provider();
72 }
73 }
74#endif
75
76 // Use platform-specific implementation
77 return fl::platforms::millis();
78}

References millis().

Referenced by CountingButton::CountingButton(), fl::Pir::Pir(), autoReset(), beat88(), animartrix_ring::SoundOrchestrator::begin(), bseconds16(), SketchHalt::check(), CFastLED::countFPS(), DbgDoSimulatedKeyboardPress(), fl::Jpeg::decodeWithTimeout(), CFastLED::delay(), fl::DemoReel100::draw(), fl::NoiseWave::draw(), fl::Pride2015::draw(), fl::TwinkleFox::drawTwinkleFox(), SketchHalt::error(), fillFrameBufferNoise(), fl::net::http::HttpStreamTransport::getCurrentTimeMs(), fl::Engine::getTime(), HandleNoteOff(), HandleNoteOn(), hours8(), loop(), millis(), millis64(), minutes16(), fl::SerialPort::parseFloat(), fl::SerialPort::parseInt(), fl::ChannelManager::pollNeededWaitSliceMs(), fl::Remote::processRpc(), rainbowWave(), ToggleButton::Read(), fl::SerialPort::readBytes(), fl::SerialPort::readBytesUntil(), readSerialStringUntil(), fl::SerialPort::readString(), readStringUntil(), fl::SerialPort::readStringUntil(), fl::Remote::scheduleFunction(), seconds16(), setup(), fl::third_party::TJpgInstanceDecoder::shouldYield(), fl::Particles1d::Particle::spawn(), fl::Particles1d::Particle::spawn(), fl::third_party::TJpgInstanceDecoder::startTick(), fl::test::XMLReporter::testCaseEnd(), ColorSelector::Update(), fl::task::Scheduler::update(), fl::task::Scheduler::update_tasks_of_type(), fl::spi::Transaction::wait(), fl::ChannelManager::waitForCondition(), fl::IChannelDriver::waitForCondition(), write_one_frame(), and fl::spi::Device::writeAsync().

+ Here is the call graph for this function: