tone-generator/tone-generator.ino

47 lines
812 B
Arduino
Raw Normal View History

2024-08-19 22:43:24 +10:00
#include "tone.hpp"
#include "tones.hpp"
#include "dac.hpp"
#include "timing.hpp"
#include "util.hpp"
#include "scheduler.hpp"
2024-08-25 18:22:48 +10:00
#include "indicator.hpp"
2024-08-19 22:43:24 +10:00
2024-08-25 18:22:48 +10:00
static unsigned long int micros_at = 0;
static bool led_state = true;
2024-08-19 22:43:24 +10:00
inline unsigned long micros_diff() {
unsigned long now = micros();
unsigned long diff = now - micros_at;
micros_at = now;
return diff;
}
void setup() {
dac::init();
2024-08-25 16:53:23 +10:00
tones::init();
scheduler::init();
2024-08-25 18:22:48 +10:00
indicator::init();
2024-08-19 22:43:24 +10:00
}
void loop() {
2024-08-25 16:53:23 +10:00
if(scheduler::running && timing::at >= scheduler::timestamp) {
scheduler::do_all();
2024-08-25 18:22:48 +10:00
indicator::update();
2024-08-19 22:43:24 +10:00
}
timing::update();
float value = 0;
2024-08-25 16:53:23 +10:00
uint32_t passed = timing::diff;
2024-08-19 22:43:24 +10:00
for(int i = 0; i < tones::active; i++) {
Tone& t = tones::all[i];
t.update(passed);
value += t.get();
}
dac::set(value);
}