最小 STM32 TimerInterrupt_Generic PlatformIO / Arduino 定时器中断闪烁示例
***注意:***如果你需要更多灵活性,请参见最小 STM32 HardwareTimer PlatformIO / Arduino 定时器中断闪烁示例,其中我们展示了如何使用 HardwareTimer 而不是 TimerInterrupt_Generic。注意 TimerInterrupt_Generic 内部使用 HardwareTimer。
这是一个在 PlatformIO / Arduino 上使用 TimerInterrupt_Generic 库使用定时器中断的最小示例,该库在 Olimex E407 上运行。它几乎可以在任何 STM32 处理器上运行,但你可能需要将 PC13 调整为连接到 LED 的引脚。该示例将每秒闪烁一次 LED。
timer_interrupt_example.cpp
#include <Arduino.h>
#include <TimerInterrupt_Generic.h>
STM32Timer tim1(TIM1);
bool ledOn = false;
void OnTimer1Interrupt() {
ledOn = !ledOn;
digitalWrite(PC13, ledOn ? LOW : HIGH);
}
void setup() {
pinMode(PC13, OUTPUT);
// 启用 TIM4
tim1.attachInterruptInterval(500000, OnTimer1Interrupt);
}
void loop() {
}Now add
platformio_lib_deps.ini
lib_deps =
khoih.prog/TimerInterrupt_Generic @ ^1.7.0到你的 platformio.ini。我的完整 platformio.ini 如下所示:
platformio_olimex_e407.ini
[env:olimex_e407]
platform = ststm32
board = olimex_e407
framework = arduino
lib_deps =
khoih.prog/TimerInterrupt_Generic @ ^1.7.0Check out similar posts by category:
PlatformIO, STM32
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow