en-us_commands:reference:itimerset
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en-us_commands:reference:itimerset [2026/09/07 21:52] – 만듦 - 바깥 편집 127.0.0.1 | en-us_commands:reference:itimerset [2026/09/12 22:54] (current) – 바깥 편집 127.0.0.1 | ||
|---|---|---|---|
| Line 15: | Line 15: | ||
| ===== Example ===== | ===== Example ===== | ||
| + | |||
| + | This uses the default callback timer (Timer2). The callback changes only a flag; serial output runs in '' | ||
| <code cpp> | <code cpp> | ||
| - | volatile bool fastTick | + | volatile bool tick = false; |
| - | void onFastTimer() { | + | void onTimer() { |
| - | | + | |
| } | } | ||
| void setup() { | void setup() { | ||
| - | ItimerSet(3, 100, onFastTimer); | + | |
| - | ItimerStart(3); | + | if (!ItimerSet(1000, onTimer)) return; // Configure a 1 s callback on the default hardware timer. |
| + | ItimerStart(); | ||
| } | } | ||
| void loop() { | void loop() { | ||
| - | if (fastTick) { | + | if (tick) { |
| - | | + | |
| + | tick = false; | ||
| + | interrupts(); | ||
| + | Serial.println(F(" | ||
| } | } | ||
| } | } | ||
| Line 37: | Line 43: | ||
| ===== Precautions ===== | ===== Precautions ===== | ||
| - | * Timer interrupt | + | * The callback runs in an interrupt. |
| - | * Do not use slow or interrupt-dependent code such as '' | + | * The callback timer without |
| - | * Normally, call '' | + | * When specifying another hardware timer, check for conflicts |
| - | * Do not use the default '' | + | * A zero interval or missing |
| - | * Explicitly using Timer1, Timer3, Timer4 or Timer5 may conflict | + | |
| - | * Configure only one '' | + | ===== Built-in Commands |
| - | * Defining an ISR for the same timer directly | + | |
| - | * '' | + | * [[: |
| + | * [[: | ||
| + | * [[: | ||
| + | * [[:en-us_commands: | ||
| [[: | [[: | ||
en-us_commands/reference/itimerset.1788785568.txt.gz · Last modified: by 127.0.0.1
