From 31aa8beefbbc9dfa4d58d572b3b7941a4428004e Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Sun, 25 Aug 2024 18:22:48 +1000 Subject: [PATCH] added indicator LED --- indicator.cpp | 19 +++++++++++++++++++ indicator.hpp | 9 +++++++++ tone-generator.ino | 6 +++++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 indicator.cpp create mode 100644 indicator.hpp diff --git a/indicator.cpp b/indicator.cpp new file mode 100644 index 0000000..08e4e70 --- /dev/null +++ b/indicator.cpp @@ -0,0 +1,19 @@ + +#include +#include "indicator.hpp" +#include "tones.hpp" + +#define LED_INDICATOR 10 + +void indicator::init() { + pinMode(LED_INDICATOR, OUTPUT); +} + +void indicator::update() { + float v = 0; + for(int i = 0; i < tones::active; i++) { + v += tones::all[i].amplitude; + } + analogWrite(LED_INDICATOR, min((int)(v * 256), 255)); +} + diff --git a/indicator.hpp b/indicator.hpp new file mode 100644 index 0000000..7dcc8fd --- /dev/null +++ b/indicator.hpp @@ -0,0 +1,9 @@ + +#pragma once + +namespace indicator { + + void init(); + void update(); +}; + diff --git a/tone-generator.ino b/tone-generator.ino index cd80a47..18d71f8 100644 --- a/tone-generator.ino +++ b/tone-generator.ino @@ -5,8 +5,10 @@ #include "timing.hpp" #include "util.hpp" #include "scheduler.hpp" +#include "indicator.hpp" -unsigned long int micros_at = 0; +static unsigned long int micros_at = 0; +static bool led_state = true; inline unsigned long micros_diff() { unsigned long now = micros(); @@ -19,11 +21,13 @@ void setup() { dac::init(); tones::init(); scheduler::init(); + indicator::init(); } void loop() { if(scheduler::running && timing::at >= scheduler::timestamp) { scheduler::do_all(); + indicator::update(); } timing::update();