hello,
I just started on Arduino and made a cool heartbeat pulse on the RGB led,
this is my hello world and want to figure out all the things I can do.
just like the timer interrupt callback.
I cannot seem to get the timer overflow going or at least cannot hit the callback.
can someone give me a hint since I am lost at this point ![]()
BR Henkjan
/// here is my hello world code:
#include <FspTimer.h>
int TimerInitDone;
void setup() {
Serial.begin(9600);
FspTimer fspTimer;
uint8_t type = GPT_TIMER;
int8_t channel = fspTimer.get_available_timer(type);
if (type != GPT_TIMER || channel == -1)
return;
if (!fspTimer.begin(TIMER_MODE_PERIODIC, type, channel, 10.0, STANDARD_DUTY_CYCLE_PERC, Timer_Callback, nullptr))
return;
if (!fspTimer.setup_overflow_irq())
return;
if (!fspTimer.open())
return;
if (!fspTimer.start())
return;
TimerInitDone = 1;
interrupts();
}
const int HeartBeatArray[] = { 1, 4, 16, 32, 64, 255, 64, 32, 16,
0, 0, 0, 0, 0, 0, 0,
1, 4, 32, 16, 4, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int i, j = 1;
void loop() {
Serial.println("Beat " + String(i++) + " - " + String(j));
if (!TimerInitDone) return;
for (int i = 0; i < (sizeof(HeartBeatArray) / sizeof(int)); i++) {
analogWrite(LEDR, 255 - HeartBeatArray[i]); // Red is fully on
delay(15);
}
}
void Timer_Callback(st_timer_callback_args* timer_args) {
j = 42;
}