tone-generator/tone-generator.ino

59 lines
1015 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"
#include "serial.hpp"
#include "eeprom.hpp"
#include "data.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() {
Tone::init();
2024-08-19 22:43:24 +10:00
dac::init();
serial::init();
eeprom::init();
2024-08-25 16:53:23 +10:00
tones::init();
2024-08-25 18:22:48 +10:00
indicator::init();
scheduler::reset();
2024-08-19 22:43:24 +10:00
}
void loop() {
if(scheduler::running) {
if(timing::at >= scheduler::timestamp) {
data::update();
scheduler::do_all();
indicator::update();
}
} else {
data::update();
2024-08-19 22:43:24 +10:00
}
timing::update();
int32_t 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 >> 8) + 127);
2024-08-19 22:43:24 +10:00
}