diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 7ba93ed..d94a939 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -11,6 +11,7 @@ #include "menu.h" #include "config.h" #include "settings.h" +#include "led.h" /* NAME: NuEVI @@ -233,9 +234,6 @@ byte slurSustain = 0; byte parallelChord = 0; byte subOctaveDouble = 0; -const int breathLedBrightness = 500; // up to 4095, PWM -const int portamLedBrightness = 500; // up to 4095, PWM - Adafruit_MPR121 touchSensor = Adafruit_MPR121(); // This is the 12-input touch sensor FilterOnePole breathFilter; @@ -291,7 +289,7 @@ void setup() { vibZero += touchRead(vibratoPin); breathCalZero += analogRead(breathSensorPin); if (biteJumper) vibZeroBite += analogRead(A7); else vibZeroBite += touchRead(bitePin); - digitalWrite( statusLedPin, i&1 ); + statusLed(i&1); delay(fastBoot?75:250); //Shorter delay for fastboot } @@ -687,7 +685,7 @@ void loop() { } else { if (slowMidi) breath(); extraController(); - statusLEDs(); + updateSensorLEDs(); doorKnobCheck(); } ccSendTime = millis(); @@ -778,23 +776,6 @@ int patchLimit(int value) { //************************************************************** -void statusLEDs() { - if (breathLevel > breathThrVal) { // breath indicator LED, labeled "B" on PCB - //analogWrite(bLedPin, map(breathLevel,0,4096,5,breathLedBrightness)); - analogWrite(bLedPin, map(constrain(breathLevel, breathThrVal, breathMaxVal), breathThrVal, breathMaxVal, 5, breathLedBrightness)); - } else { - analogWrite(bLedPin, 0); - } - if (portIsOn) { // portamento indicator LED, labeled "P" on PCB - //analogWrite(pLedPin, map(biteSensor,0,4096,5,portamLedBrightness)); - analogWrite(pLedPin, map(constrain(oldport, 0, 127), 0, 127, 5, portamLedBrightness)); - } else { - analogWrite(pLedPin, 0); - } -} - -//************************************************************** - void breath() { int breathCCval, breathCCvalFine,breathCC2val; unsigned int breathCCvalHires; @@ -1170,24 +1151,3 @@ void readSwitches() { } lastFingering = fingeredNoteRead; } - - - -void statusLedOn() { - digitalWrite(statusLedPin, HIGH); -} - -void statusLedOff() { - digitalWrite(statusLedPin, LOW); -} - -void statusLedFlip() { - digitalWrite(statusLedPin, !digitalRead(statusLedPin)); -} - -void statusLedFlash(uint16_t delayTime) { - statusLedOff(); - delay(delayTime/2); - statusLedOn(); - delay(delayTime/2); -} diff --git a/NuEVI/config.h b/NuEVI/config.h index 0ebceae..84520ea 100644 --- a/NuEVI/config.h +++ b/NuEVI/config.h @@ -30,4 +30,9 @@ #define ttouchHiLimit 1900 +#define MIN_LED_BRIGHTNESS 5 // lowest PWM value that still is visible +#define BREATH_LED_BRIGHTNESS 500 // up to 4095, PWM +#define PORTAM_LED_BRIGHTNESS 500 // up to 4095, PWM + + #endif diff --git a/NuEVI/globals.h b/NuEVI/globals.h index 4cb0a8b..03fabd6 100644 --- a/NuEVI/globals.h +++ b/NuEVI/globals.h @@ -116,6 +116,10 @@ extern int vibZeroBite; extern int vibThrBite; extern int vibThrBiteLo; +extern int breathLevel; +extern byte portIsOn; +extern int oldport; + // Key variables, TRUE (1) for pressed, FALSE (0) for not pressed extern byte K1; // Valve 1 (pitch change -2) extern byte K2; // Valve 2 (pitch change -1) diff --git a/NuEVI/led.cpp b/NuEVI/led.cpp new file mode 100644 index 0000000..0f0d2f4 --- /dev/null +++ b/NuEVI/led.cpp @@ -0,0 +1,48 @@ +#include +#include "hardware.h" +#include "globals.h" +#include "config.h" + +// Do things with status LED. +void statusLedOn() { + digitalWrite(statusLedPin, HIGH); +} + +void statusLedOff() { + digitalWrite(statusLedPin, LOW); +} + +void statusLed(bool state) { + digitalWrite(statusLedPin, state); +} + +void statusLedFlip() { + digitalWrite(statusLedPin, !digitalRead(statusLedPin)); +} + +void statusLedFlash(uint16_t delayTime) { + statusLedOff(); + delay(delayTime/2); + statusLedOn(); + delay(delayTime/2); +} + +void statusLedBlink() { + statusLedFlash(300); + statusLedFlash(300); +} + +void updateSensorLEDs() { + if (breathLevel > breathThrVal) { // breath indicator LED, labeled "B" on PCB + //analogWrite(bLedPin, map(breathLevel,0,4096,5,breathLedBrightness)); + analogWrite(bLedPin, map(constrain(breathLevel, breathThrVal, breathMaxVal), breathThrVal, breathMaxVal, MIN_LED_BRIGHTNESS, BREATH_LED_BRIGHTNESS)); + } else { + analogWrite(bLedPin, 0); + } + if (portIsOn) { // portamento indicator LED, labeled "P" on PCB + //analogWrite(pLedPin, map(biteSensor,0,4096,5,portamLedBrightness)); + analogWrite(pLedPin, map(constrain(oldport, 0, 127), 0, 127, MIN_LED_BRIGHTNESS, PORTAM_LED_BRIGHTNESS)); + } else { + analogWrite(pLedPin, 0); + } +} \ No newline at end of file diff --git a/NuEVI/led.h b/NuEVI/led.h new file mode 100644 index 0000000..cd893d1 --- /dev/null +++ b/NuEVI/led.h @@ -0,0 +1,12 @@ +#ifndef __LED_H +#define __LED_H + +void statusLedOn(); +void statusLedOff(); +void statusLedFlip(); +void statusLed(bool state); +void statusLedFlash(uint16_t delayTime); +void statusLedBlink(); +void updateSensorLEDs(); + +#endif \ No newline at end of file diff --git a/NuEVI/menu.cpp b/NuEVI/menu.cpp index 8fec04d..5788e68 100644 --- a/NuEVI/menu.cpp +++ b/NuEVI/menu.cpp @@ -10,6 +10,7 @@ #include "globals.h" #include "midi.h" #include "numenu.h" +#include "led.h" enum CursorIdx { EMain, @@ -1228,17 +1229,6 @@ static bool updatePage(const MenuPage *page, KeyState &input, uint32_t timeNow) return redraw; } -//*********************************************************** -// This should be moved to a separate file/process that handles only led -static void statusBlink() { - digitalWrite(statusLedPin,LOW); - delay(150); - digitalWrite(statusLedPin,HIGH); - delay(150); - digitalWrite(statusLedPin,LOW); - delay(150); - digitalWrite(statusLedPin,HIGH); -} //*********************************************************** @@ -1391,12 +1381,12 @@ static bool idlePageUpdate(KeyState& __unused input, uint32_t __unused timeNow) legacyBrAct = !legacyBrAct; dipSwBits = dipSwBits ^ (1<<2); writeSetting(DIPSW_BITS_ADDR,dipSwBits); - statusBlink(); + statusLedBlink(); } else if ((exSensor >= ((extracThrVal+extracMaxVal)/2))) { // switch pb pad activated legacy settings control on/off legacy = !legacy; dipSwBits = dipSwBits ^ (1<<1); writeSetting(DIPSW_BITS_ADDR,dipSwBits); - statusBlink(); + statusLedBlink(); } else if (pinkyKey && !specialKey){ //hold pinky key for rotator menu, and if too high touch sensing blocks regular menu, touching special key helps display.ssd1306_command(SSD1306_DISPLAYON); menuState= ROTATOR_MENU; diff --git a/simulation/Makefile b/simulation/Makefile index 903471c..71ec82e 100644 --- a/simulation/Makefile +++ b/simulation/Makefile @@ -30,6 +30,7 @@ CXXFILES= ../NuEVI/menu.cpp \ ../NuEVI/adjustmenu.cpp \ ../NuEVI/midi.cpp \ ../NuEVI/settings.cpp \ + ../NuEVI/led.cpp \ src/nuevisim.cpp \ src/simeeprom.cpp \ src/Print.cpp \