Think I may have, more or less, solved the problem with `IntervalTimers`
Code:
#include <Arduino.h>
const int g_slow_output_pin = 0; // pin number
const int g_slow_output_interval = 100000; // us
const int g_slow_output_high_time = 250; // us
const int g_fast_output_pin = 1; // pin number
const int g_fast_output_interval = 50000; // us
const int g_fast_output_high_time = 10; // us
IntervalTimer g_timer_slow;
IntervalTimer g_timer_slow_off;
IntervalTimer g_timer_fast;
IntervalTimer g_timer_fast_off;
elapsedMillis g_ms_since_start;
unsigned long int g_stamp_ms;
void turn_slow_output_off() {
g_timer_slow_off.end();
digitalWriteFast(g_slow_output_pin, LOW);
}
void slow_output_callback() {
unsigned long stamp = g_ms_since_start;
digitalWriteFast(g_slow_output_pin, HIGH);
g_timer_slow_off.begin(turn_slow_output_off, g_slow_output_high_time);
Serial.print("slow stamp [ms]: ");
Serial.println(stamp);
}
void turn_fast_output_off() {
g_timer_fast_off.end();
digitalWriteFast(g_fast_output_pin, LOW);
}
void fast_output_callback() {
unsigned long stamp = g_ms_since_start;
digitalWriteFast(g_fast_output_pin, HIGH);
g_timer_fast_off.begin(turn_fast_output_off, g_fast_output_high_time);
Serial.print("fast stamp [ms]: ");
Serial.println(stamp);
}
void setup() {
Serial.begin(9600);
pinMode(g_slow_output_pin, OUTPUT);
pinMode(g_fast_output_pin, OUTPUT);
g_timer_slow.begin(slow_output_callback, g_slow_output_interval);
g_timer_fast.begin(fast_output_callback, g_fast_output_interval);
}
void loop() {}
but I'll give TimerTool a look, could perhaps make what I've done better/more readable
Edit: just a question I thought of, is there any major advantage to using something like TimerTool versus what I've done.