Minimal STM32 TimerInterrupt_Generic PlatformIO / Arduino Timer-Interrupt Blink-Beispiel
English
Deutsch
Hinweis: Wenn mehr Flexibilität benötigt wird, siehe Minimal STM32 HardwareTimer PlatformIO / Arduino Timer-Interrupt Blink-Beispiel, wo gezeigt wird, wie HardwareTimer statt TimerInterrupt_Generic verwendet wird. Beachten, dass TimerInterrupt_Generic intern HardwareTimer verwendet.
Dies ist ein minimales Beispiel für die Verwendung von Timer-Interrupts auf PlatformIO / Arduino mit der TimerInterrupt_Generic-Bibliothek, die auf dem Olimex E407 läuft. Es läuft auf fast jedem STM32-Prozessor, aber möglicherweise muss PC13 an den mit der LED verbundenen PIN angepasst werden. Das Beispiel lässt die LED einmal pro Sekunde blinken.
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);
// Enable TIM4
tim1.attachInterruptInterval(500000, OnTimer1Interrupt);
}
void loop() {
}Nun hinzufügen
platformio_lib_deps.ini
lib_deps =
khoih.prog/TimerInterrupt_Generic @ ^1.7.0zur platformio.ini. Meine vollständige platformio.ini sieht so aus:
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