From 3e2384e0b431bdfc4236d3418c90ac9a0ac23a0b Mon Sep 17 00:00:00 2001 From: ScruffR Date: Fri, 1 Jul 2016 13:21:58 +0200 Subject: [PATCH 1/4] Add support for sharp ( --- firmware/InternetButton.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/firmware/InternetButton.cpp b/firmware/InternetButton.cpp index 731573e..5bf2a01 100644 --- a/firmware/InternetButton.cpp +++ b/firmware/InternetButton.cpp @@ -216,12 +216,7 @@ void InternetButton::playSong(String song){ while(duration != NULL){ note = strtok(NULL,","); - Serial.println(note); duration = strtok(NULL,", \n"); - Serial.println(duration); - //if(atoi(duration) <= 0){ - // break; - //} playNote(note,atoi(duration)); } } @@ -233,11 +228,17 @@ void InternetButton::playNote(String note, int duration){ //if(9 - int(command.charAt(1)) != null){ char octavo[5]; - String tempString = note.substring(1,2); + String tempString = note.substring(note.length()-1,note.length()); tempString.toCharArray(octavo,5); octave = atoi(octavo); //} + Serial.print(note); + Serial.print(" "); + Serial.print(octave); + Serial.print(" "); + Serial.println(duration); + if(duration != 0){ duration = 1000/duration; } @@ -272,6 +273,16 @@ void InternetButton::playNote(String note, int duration){ //return -1; } + switch(note.charAt(1)) { + case '#': // sharp + noteNum++; + break; + case 'b': // flat + noteNum--; + default: + break; + } + // based on equation at http://www.phy.mtu.edu/~suits/NoteFreqCalcs.html and the Verdi tuning // fn = f0*(2^1/12)^n where n = number of half-steps from the reference frequency f0 freq = float(256*pow(1.05946,( 12.0*(octave-4) +noteNum))); From a645a11a99f726173d3e0580bd30a425b1e542ed Mon Sep 17 00:00:00 2001 From: ScruffR Date: Fri, 1 Jul 2016 13:27:12 +0200 Subject: [PATCH 2/4] Add support for sharp (#) and flat (b) notes --- firmware/InternetButton.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/InternetButton.cpp b/firmware/InternetButton.cpp index 5bf2a01..9f84db5 100644 --- a/firmware/InternetButton.cpp +++ b/firmware/InternetButton.cpp @@ -204,6 +204,7 @@ uint8_t InternetButton::lowestLed(){ return ledPos; } +// song string can look like this "C4,1,C#4,1,Db4,1" for sharp (#) and flat (b) notes void InternetButton::playSong(String song){ char inputStr[200]; song.toCharArray(inputStr,200); From 93c43b83c204daa760577f59c1abe026a0d74b2d Mon Sep 17 00:00:00 2001 From: ScruffR Date: Fri, 1 Jul 2016 13:52:00 +0200 Subject: [PATCH 3/4] Add functions whichButtonsOn()/firstButtonOn() `whichButtonsOn()` returns a `uint8_t` that has a bit set for each button (button1 .. bit1 .. 0b0000 0010, button2 .. bit2 ...) `firstButtonOn()` returns the number of the lowest number button 1, 2, 3 or 4.. --- firmware/InternetButton.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/firmware/InternetButton.cpp b/firmware/InternetButton.cpp index 9f84db5..a37e5e6 100644 --- a/firmware/InternetButton.cpp +++ b/firmware/InternetButton.cpp @@ -152,6 +152,24 @@ uint8_t InternetButton::allButtonsOff(){ } } +uint8_t InternetButton::whichButtonsOn(){ + uint8_t ret = 0; + ret |= digitalRead(b1) << 1; // bit 1 0b00000010 + ret |= digitalRead(b2) << 2; // bit 2 0b00000100 + ret |= digitalRead(b3) << 3; // bit 3 0b00001000 + ret |= digitalRead(b4) << 4; // bit 4 0b00010000 + return ret; +} + +uint8_t InternetButton::firstButtonOn(){ + uint8_t ret = 0; + if (digitalRead(b1)) return 1; + if (digitalRead(b2)) return 2; + if (digitalRead(b3)) return 3; + if (digitalRead(b4)) return 4; + return 0; +} + void InternetButton::rainbow(uint8_t wait) { uint16_t i, j; From 20a1f166f68514441d3f80aa9c3453cbaf2c8943 Mon Sep 17 00:00:00 2001 From: ScruffR Date: Fri, 1 Jul 2016 13:55:20 +0200 Subject: [PATCH 4/4] Add functions whichButtonsOn()/firstButtonOn() `whichButtonsOn()` returns a `uint8_t` that contains a bit mask for each pressed button (button1 .. bit1 .. 0b00000010, button2 ..bit2 .. 0b00000100, ...) `firstButtonOn()` returns the number of the lowest number button currently pressed (1, 2, 3 or 4). --- firmware/InternetButton.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/firmware/InternetButton.h b/firmware/InternetButton.h index 78eff01..7ed79ce 100644 --- a/firmware/InternetButton.h +++ b/firmware/InternetButton.h @@ -45,6 +45,8 @@ class InternetButton { buttonOn(uint8_t i), allButtonsOn(void), allButtonsOff(void), + whichButtonsOn(), + firstButtonOn(), lowestLed(void); int readX(void),