From a5385a9ec19d0272ffb95e5f3c9871c8a8f4d352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20St=C3=A4ck?= Date: Sat, 27 Jul 2019 00:06:52 +0200 Subject: [PATCH] Wrap status led usage in neat functions --- NuEVI/NuEVI.ino | 61 +++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/NuEVI/NuEVI.ino b/NuEVI/NuEVI.ino index 7242683..6fc1f62 100644 --- a/NuEVI/NuEVI.ino +++ b/NuEVI/NuEVI.ino @@ -305,11 +305,8 @@ void setup() { vibThrBiteLo = vibZeroBite + vibSquelchBite; if(!fastBoot) { - digitalWrite(statusLedPin, LOW); - delay(250); - digitalWrite(statusLedPin,HIGH); - delay(250); - digitalWrite(statusLedPin,LOW); + statusLedFlash(500); + statusLedOff(); showVersion(); @@ -328,7 +325,7 @@ void setup() { //Serial.begin(9600); // debug - digitalWrite(statusLedPin,HIGH); // Switch on the onboard LED to indicate power on/ready + statusLedOn(); // Switch on the onboard LED to indicate power on/ready } @@ -700,9 +697,9 @@ void loop() { // this is one of the big reasons the display is for setup use only drawSensorPixels(); // live sensor monitoring for the setup screens if (rotatorOn || slurSustain || parallelChord || subOctaveDouble || gateOpen) { - digitalWrite(statusLedPin, !digitalRead(statusLedPin)); - } else if (!digitalRead(statusLedPin)) { - digitalWrite(statusLedPin, HIGH); + statusLedFlip(); + } else { + statusLedOn(); } pixelUpdateTime = millis(); } @@ -944,10 +941,10 @@ void pitch_bend() { pitchBend = constrain(pitchBend, 0, 16383); if (subVibSquelch && (8192 != pitchBend)) { - digitalWrite(statusLedPin, LOW); + statusLedOff(); vibLedOff = 1; } else if (vibLedOff) { - digitalWrite(statusLedPin, HIGH); + statusLedOn(); vibLedOff = 0; } @@ -972,25 +969,14 @@ void doorKnobCheck() { if ((touchValue[K4Pin] < ctouchThrVal) && (touchValue[R1Pin] < ctouchThrVal) && (touchValue[R2Pin] < ctouchThrVal) && (touchValue[R3Pin] < ctouchThrVal)) { // doorknob grip on canister if (!gateOpen && (pbUp > ((pitchbMaxVal + pitchbThrVal) / 2))) { gateOpen = 1; - digitalWrite(statusLedPin, LOW); - delay(50); - digitalWrite(statusLedPin, HIGH); - delay(50); + statusLedFlash(100); } else if (gateOpen && (pbDn > ((pitchbMaxVal + pitchbThrVal) / 2))) { gateOpen = 0; midiPanic(); - digitalWrite(statusLedPin, LOW); - delay(50); - digitalWrite(statusLedPin, HIGH); - delay(50); - digitalWrite(statusLedPin, LOW); - delay(50); - digitalWrite(statusLedPin, HIGH); - delay(50); - digitalWrite(statusLedPin, LOW); - delay(50); - digitalWrite(statusLedPin, HIGH); - delay(700); + statusLedFlash(100); + statusLedFlash(100); + statusLedFlash(100); + delay(600); } } } else if (gateOpen) { @@ -1184,3 +1170,24 @@ 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); +}