EA_Timer is a simple but powerful timer management library that you can use in STM32 projects. With this library, you can easily manage multiple timers and assign special functions to each. You can set timers to work once or continuously.
- You can create as many timers as you want
- Each timer has its own number
- You can check if the timer is working
- You can find out how much time is left for the timer
- You can easily manage timers using Lambda functions
- You can set timers to work once or continuously
First add the library to your project:
- Copy
EA_Timer.handEA_Timer.cppfiles to your project - Include the header in the file you will use:
#include "EA_Timer.h"EA_Timer timer;uint8_t timerId = timer.startTimer(5000, []() {
// Actions to be taken when the timer expires
// Example: Turn the LED on/off
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});uint8_t timerId = timer.startAutoRestartTimer(5000, []() {
// Actions to be taken when the timer expires
// This timer will automatically restart
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});timer.stopTimer(timerId);timer.stopAllTimers();if (timer.isTimerActive(timerId)) {
// Timer is still running
}uint32_t remaining = timer.getRemainingTime(timerId);To check timers in the main loop:
while (1) {
timer.processTimers();
// ... other processes ...
}EA_Timer ledTimer;
// Turn the LED on/off once after 5 seconds
uint8_t ledTimerId = ledTimer.startTimer(5000, []() {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});
// In the main loop
while (1) {
ledTimer.processTimers();
HAL_Delay(1);
}EA_Timer ledTimer;
// Turn the LED on/off once every 1 second
uint8_t ledTimerId = ledTimer.startAutoRestartTimer(1000, []() {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});
// In the main loop
while (1) {
ledTimer.processTimers();
HAL_Delay(1);
}EA_Timer multiTimer;
// Timer 1: Every 2 seconds (continuous)
uint8_t timer1Id = multiTimer.startAutoRestartTimer(2000, []() {
// Process 1
});
// Timer 2: Once after 5 seconds
uint8_t timer2Id = multiTimer.startTimer(5000, []() {
// Process 2
});
// In the main loop
while (1) {
multiTimer.processTimers();
HAL_Delay(1);
}- Timers work in milliseconds
- Each timer has its own unique number
- One-time timers clean themselves up when they are done
- Timers that run continuously continue until you stop them
- Don't forget to call the
processTimers()function regularly - Creating too many timers can fill up RAM
- If the timer number is not found:
stopTimer()andisTimerActive()functions do nothinggetRemainingTime()function returns 0
- If memory is insufficient:
startTimer()andstartAutoRestartTimer()functions return 0- TR
EA_Timer, STM32 projelerinde kullanabileceğiniz basit ama güçlü bir timer yönetim kütüphanesidir. Bu kütüphane sayesinde birden fazla timer'ı kolayca yönetebilir, her birine özel işlevler atayabilirsiniz. Timer'ları tek seferlik veya sürekli çalışacak şekilde ayarlayabilirsiniz.
- İstediğiniz kadar timer oluşturabilirsiniz
- Her timer'ın kendine özel bir numarası olur
- Timer'ın çalışıp çalışmadığını kontrol edebilirsiniz
- Timer'ın ne kadar süresi kaldığını öğrenebilirsiniz
- Lambda fonksiyonları kullanarak timer'ları kolayca yönetebilirsiniz
- Timer'ları tek seferlik veya sürekli çalışacak şekilde ayarlayabilirsiniz
Önce kütüphaneyi projenize ekleyin:
EA_Timer.hveEA_Timer.cppdosyalarını projenize kopyalayın- Kullanacağınız dosyada header'ı dahil edin:
#include "EA_Timer.h"EA_Timer timer;uint8_t timerId = timer.startTimer(5000, []() {
// Timer süresi dolduğunda yapılacak işlemler
// Örnek: LED'i yak/söndür
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});uint8_t timerId = timer.startAutoRestartTimer(5000, []() {
// Timer süresi dolduğunda yapılacak işlemler
// Bu timer otomatik olarak yeniden başlayacak
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});timer.stopTimer(timerId);timer.stopAllTimers();if (timer.isTimerActive(timerId)) {
// Timer hala çalışıyor
}uint32_t remaining = timer.getRemainingTime(timerId);Ana döngüde timer'ları kontrol etmek için:
while (1) {
timer.processTimers();
// ... diğer işlemler ...
}EA_Timer ledTimer;
// LED'i 5 saniye sonra bir kez yak/söndür
uint8_t ledTimerId = ledTimer.startTimer(5000, []() {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});
// Ana döngüde
while (1) {
ledTimer.processTimers();
HAL_Delay(1);
}EA_Timer ledTimer;
// LED'i her 1 saniyede bir yak/söndür
uint8_t ledTimerId = ledTimer.startAutoRestartTimer(1000, []() {
HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
});
// Ana döngüde
while (1) {
ledTimer.processTimers();
HAL_Delay(1);
}EA_Timer multiTimer;
// Timer 1: Her 2 saniyede bir (sürekli)
uint8_t timer1Id = multiTimer.startAutoRestartTimer(2000, []() {
// İşlem 1
});
// Timer 2: 5 saniye sonra bir kez
uint8_t timer2Id = multiTimer.startTimer(5000, []() {
// İşlem 2
});
// Ana döngüde
while (1) {
multiTimer.processTimers();
HAL_Delay(1);
}- Timer'lar milisaniye cinsinden çalışır
- Her timer'ın kendine özel bir numarası vardır
- Tek seferlik timer'lar işi bitince kendini temizler
- Sürekli çalışan timer'lar siz durdurana kadar devam eder
processTimers()fonksiyonunu düzenli olarak çağırmayı unutmayın- Çok fazla timer oluşturmak RAM'i doldurabilir
-
Timer numarası bulunamazsa:
stopTimer()veisTimerActive()fonksiyonları hiçbir şey yapmazgetRemainingTime()fonksiyonu 0 döndürür
-
Bellek yetersizse:
startTimer()vestartAutoRestartTimer()fonksiyonları 0 döndürür