Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

19 Mastering Time with millis

Автор: MICRO_CONTROLER & AUTOMATION

Загружено: 2026-01-18

Просмотров: 1

Описание:

This source provides a comprehensive guide to Arduino time functions, specifically explaining how to use delay, delayMicroseconds, millis, and micros. The tutorial highlights that while delay functions are simple for pausing code, they possess the significant disadvantage of freezing the program, which can cause critical delays in sensor detection or real-time responses. To overcome this, the author demonstrates how delayMicroseconds can be used to manually generate PWM pulses on non-PWM pins to control LED brightness. Furthermore, the video emphasizes the power of the millis function, which allows for non-blocking code by tracking the time elapsed since the board was powered on. By using time-based variables instead of pauses, programmers can execute multiple tasks simultaneously, such as blinking an LED without stopping the rest of the script. Finally, the text briefly mentions micros for high-precision timing, noting that it functions similarly to millis but operates on a microsecond scale.

How do delay and millis functions differ regarding program execution and multitasking capabilities?

What are the specific trade-offs between millisecond and microsecond timing functions in Arduino?

How can timing functions be utilized to generate custom signals without using PWM?


The provided source is a transcript of a tutorial video focused on Arduino time functions, specifically explaining how they work, their advantages, and their limitations.

Below is a detailed breakdown of the time functions covered in the video:

1. delay() Function

• Purpose: This function is used to freeze the execution of the code for a specific duration.
• Units: It accepts time in milliseconds (ms), where 1,000 ms equals 1 second.
• Data Type: It uses an unsigned long data type, which can hold a maximum value of approximately 4.2 billion, allowing a code to be paused for up to 50 days.

• Major Disadvantage: Because it "freezes" the program, the Arduino cannot check other conditions (like sensor inputs) during the delay period. For example, an obstacle-avoiding robot using delay() might crash because it cannot detect an obstacle while the code is paused.

2. delayMicroseconds() Function

• Purpose: Similar to delay(), it freezes the program but for much smaller intervals.
• Units: It accepts time in microseconds (µs) (1 second = 1,000,000 µs).
• Data Type: It uses an unsigned int, with a maximum value of 65,535 (approximately 65.5 ms).
• Limitations: It is not precise for values larger than 16,383 µs. If a longer delay is needed, the source recommends using the standard delay() function instead.
• Unique Application: By toggling a digital pin "on" and "off" for micro-intervals using this function, you can generate a custom PWM (Pulse Width Modulation) pulse on any standard digital pin to control LED brightness or motor speed, even if the pin isn't a dedicated PWM pin.

3. millis() Function

• Purpose: It acts like an internal clock that starts running as soon as the Arduino is powered on or reset. It returns the number of milliseconds that have passed since the program started.
• Data Type: It uses an unsigned long and will reset to zero after approximately 50 days.
• Advantages: Unlike delay(), millis() is non-blocking. It allows you to perform tasks (like blinking an LED) while simultaneously checking other conditions in real-time without freezing the program.
• Reset Triggers: The millis() count resets to zero if the Arduino is physically reset or if the Serial Monitor is opened while connected to a computer.

4. micros() Function

• Purpose: This function is identical in logic to millis(), but it returns the elapsed time in microseconds.
• Use Case: It is ideal for applications requiring extremely high-precision timing for very small intervals.
• Reset Time: While millis() lasts 50 days, the micros() function resets every 70 minutes.

Comparison Summary
Function Unit Blocking? Max Duration / Reset
delay() Milliseconds Yes (Freezes code) ~50 days
delayMicroseconds() Microseconds Yes (Freezes code) ~65.5 ms (Precise only to 16.3 ms)
millis() Milliseconds No (Continuous) Resets after ~50 days
micros() Microseconds No (Continuous) Resets after ~70 minute

Analogy to Solidify Understanding: Think of delay() like a stopwatch that forces you to close your eyes while it counts; you can't see or do anything else until it stops. In contrast, millis() is like a clock on the wall; you can look at it to see how much time has passed while you continue to cook, clean, or watch for visitors at the door.

Explain the disadvantage of using delay for obstacle detection.

Compare the data types of delay and delayMicroseconds functions.

After how many days does the millis function reset?

19  Mastering Time with millis

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

9   Arduino s Analog World

9 Arduino s Analog World

Для Чего РЕАЛЬНО Нужен был ГОРБ Boeing 747?

Для Чего РЕАЛЬНО Нужен был ГОРБ Boeing 747?

Types of Quantitative Research

Types of Quantitative Research

Чем ОПАСЕН МАХ? Разбор приложения специалистом по кибер безопасности

Чем ОПАСЕН МАХ? Разбор приложения специалистом по кибер безопасности

STM32 после Arduino: с чего начать (Есть субтитры)

STM32 после Arduino: с чего начать (Есть субтитры)

Суть линейной алгебры: #14. Собственные векторы и собственные значения [3Blue1Brown]

Суть линейной алгебры: #14. Собственные векторы и собственные значения [3Blue1Brown]

19  Mastering Time with millis

19 Mastering Time with millis

MS-DOS Laplink — последовательная передача данных RS232

MS-DOS Laplink — последовательная передача данных RS232

Как электростатические двигатели нарушают все правила

Как электростатические двигатели нарушают все правила

20 САМЫХ МАЛЕНЬКИХ ЛЕТАТЕЛЬНЫХ АППАРАТОВ В МИРЕ

20 САМЫХ МАЛЕНЬКИХ ЛЕТАТЕЛЬНЫХ АППАРАТОВ В МИРЕ

Покойся с миром, Arduino и Open Hardware... спасибо Qualcomm

Покойся с миром, Arduino и Open Hardware... спасибо Qualcomm

КОЗЫРЕВ - астрофизик ДОКАЗАЛ, что ВРЕМЯ это ЭНЕРГИЯ: дважды СИДЕЛ, приговорён к РАССТРЕЛУ

КОЗЫРЕВ - астрофизик ДОКАЗАЛ, что ВРЕМЯ это ЭНЕРГИЯ: дважды СИДЕЛ, приговорён к РАССТРЕЛУ

Как работают ДАТЧИКИ ХОЛЛА? Самое понятное объяснение!

Как работают ДАТЧИКИ ХОЛЛА? Самое понятное объяснение!

ESP32, STM32, NRF52 или RP2040 — что лучше всего подойдет для вашего продукта?

ESP32, STM32, NRF52 или RP2040 — что лучше всего подойдет для вашего продукта?

Механизмы, которые должен знать КАЖДЫЙ инженер-механик

Механизмы, которые должен знать КАЖДЫЙ инженер-механик

The Windows 11 Disaster That's Killing Microsoft

The Windows 11 Disaster That's Killing Microsoft

8   Listening with digital   Read

8 Listening with digital Read

Синтезировал СЛАДКУЮ вату из ОБЫЧНОЙ ваты 🧪

Синтезировал СЛАДКУЮ вату из ОБЫЧНОЙ ваты 🧪

Почему простые числа образуют эти спирали? | Теорема Дирихле и пи-аппроксимации

Почему простые числа образуют эти спирали? | Теорема Дирихле и пи-аппроксимации

Код работает в 100 раз медленнее из-за ложного разделения ресурсов.

Код работает в 100 раз медленнее из-за ложного разделения ресурсов.

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com