#include "tone.hpp" #include "tones.hpp" #include "dac.hpp" #include "timing.hpp" #include "util.hpp" #include "scheduler.hpp" #include "indicator.hpp" #include "data.hpp" static unsigned long int micros_at = 0; static bool led_state = true; inline unsigned long micros_diff() { unsigned long now = micros(); unsigned long diff = now - micros_at; micros_at = now; return diff; } void setup() { Tone::init(); dac::init(); data::init(); tones::init(); scheduler::init(); indicator::init(); } void loop() { if(scheduler::running) { if(timing::at >= scheduler::timestamp) { scheduler::do_all(); indicator::update(); } } else { if(data::check()) { scheduler::do_next(); tones::recalc(); } } timing::update(); int32_t value = 0; uint32_t passed = timing::diff; for(int i = 0; i < tones::active; i++) { Tone& t = tones::all[i]; t.update(passed); value += t.get(); } dac::set((value >> 8) + 127); }