Bluetooth Enabled Keyboard/Synthesizer for mbed

Dependencies:   mbed 4DGL-uLCD-SE SDFileSystem mbed-rtos

Revision:
2:f06ba516b1ad
Parent:
1:830a669cacbe
Child:
3:3aba1d783730
--- a/main.cpp	Fri Apr 15 21:17:15 2016 +0000
+++ b/main.cpp	Wed Apr 27 21:13:45 2016 +0000
@@ -3,15 +3,9 @@
 Serial PC(USBTX,USBRX);
 DigitalOut myled(LED1);
 DigitalOut myled4(LED4);
- //Test
 //global variables for main and interrupt routine
 volatile bool readyFlag = true;
-volatile int  bnum = 0;
-volatile int  bhit  ;
 volatile char keyPress;
-//state used to remember previous characters read in a button message
-enum statetype {start = 0, got_exclm, got_B, got_num, got_hit};
-statetype state = start;
 //Interrupt routine to parse message with one new character per serial RX interrupt
 void parse_message()
 {
@@ -23,53 +17,112 @@
     //PC.printf("Value of keyPress is: %c\n\r",keyPress);
 }
  
+ 
+ 
+WaveType myWave = sine; // default to sine wave
+int currentOctave = 4; // default to 4 because thats where middle C is
+ 
+ 
 int main()
 {
 //attach interrupt function for each new Bluetooth serial character
     Blue.attach(&parse_message,Serial::RxIrq);
     while(1) {
         //check for a new button message ready
-        if((keyPress=='Z') && (readyFlag))// button Z pressed
+        if((keyPress == C_KEY) && (readyFlag))// button Z pressed
         {
-            PC.printf("Got an Z");
+            PC.printf("Got n Z");
             readyFlag = false;
             // Play note that corresponds to Z
             }
-        else if((keyPress =='X') && (readyFlag)) // button X pressed
+        else if((keyPress == D_KEY) && (readyFlag)) // button X pressed
             {
                 PC.printf("Got an X");
             // Play note that corresponds to X
             }
-        else if((keyPress =='C' && (readyFlag)){} // button C pressed
+        else if((keyPress == E_KEY && (readyFlag)){} // button C pressed
             // Play note that corresponds to C
-        else if((keyPress =='V') && (readyFlag)){} // button V pressed
+        else if((keyPress == F_KEY) && (readyFlag)){} // button V pressed
             // Play note that corresponds to V
-        else if((keyPress =='B') && (readyFlag)){} // button B pressed
+        else if((keyPress == G_KEY) && (readyFlag)){} // button B pressed
             // Play note that corresponds to B
-        else if((keyPress =='N') && (readyFlag)){} // button N pressed
+        else if((keyPress == A_KEY) && (readyFlag)){} // button N pressed
             // Play note that corresponds to N
-        else if((keyPress =='M') && (readyFlag)){} // button M pressed
+        else if((keyPress == B_KEY) && (readyFlag)){} // button M pressed
             // Play note that corresponds to M
-        else if((keyPress =='O') && (readyFlag)){} // button O pressed
-            // Lower an octave
-        else if((keyPress =='L') && (readyFlag)){} // button L pressed
+        else if((keyPress == RAISE_OCTAVE_KEY) && (readyFlag)){ // button O pressed
             // Raise an octave
-        else if((keyPress =='Q') && (readyFlag)){} // button Q pressed
+            currentOctave++;
+            }
+        else if((keyPress == LOWER_OCTAVE_KEY) && (readyFlag)){ // button L pressed
+            // Lower an octave
+            currentOctave--;
+            }
+        else if((keyPress == RAISE_ATTACK_KEY) && (readyFlag)){ // button Q pressed
             // Raise Attack Value
-        else if((keyPress =='A') && (readyFlag)){} // button A pressed
+            currentAttackVal++;
+            }
+        else if((keyPress == LOWER_ATTACK_KEY) && (readyFlag)){ // button A pressed
             // Lower Attack Value
-        else if((keyPress =='W') && (readyFlag)){} // button W pressed
+            currentAttackVal--;
+            }
+        else if((keyPress == RAISE_DELAY_KEY) && (readyFlag)){ // button W pressed
             // Raise Delay Value
-        else if((keyPress =='S') && (readyFlag)){} // button S pressed
+            currentDelayVal++;
+            }
+        else if((keyPress == LOWER_DELAY_KEY) && (readyFlag)){ // button S pressed
             // Lower Delay Value
-        else if((keyPress =='E') && (readyFlag)){} // button E pressed
+            currentDelayVal--;
+            }
+        else if((keyPress == RAISE_SUSTAIN_KEY) && (readyFlag)){ // button E pressed
             // Raise Sustain Value
-        else if((keyPress =='D') && (readyFlag)){} // button D pressed
+            currentSustainVal++;
+            }
+        else if((keyPress == LOWER_SUSTAIN_KEY) && (readyFlag)){ // button D pressed
             // Lower Sustain Value
-        else if((keyPress =='R') && (readyFlag)){} // button R pressed
+            currentSustainVal--;
+            }
+        else if((keyPress == RAISE_RELEASE_KEY) && (readyFlag)){ // button R pressed
             // Raise Release Value
-        else if((keyPress =='F') && (readyFlag)){} // button F pressed
+            currentReleaseVal++;
+            }
+        else if((keyPress == LOWER_RELEASE_KEY) && (readyFlag)){ // button F pressed
             // Lower Release Value
+            currentReleaseVal--;
+            }
+        else if((keyPress == CHANGE_WAVESHAPE_UP) && (readyFlag)){ // button T pressed
+            // Change waveform shape to next waveform type
+            switch(myWave){
+                case sine:
+                    myWave = square;
+                    break;
+                case square:
+                    myWave = sawtooth;
+                    break;
+                case sawtooth:
+                    myWave = sine;
+                    break;
+                default:
+                break;
+                }
+            }
+        else if((keyPress == CHANGE_WAVESHAPE_DOWN) && (readyFlag)){ // button G pressed
+            // Change waveform shape to previous waveform type
+            switch(myWave){
+                case sine:
+                    myWave = sawtooth;
+                    break;
+                case square:
+                    myWave = sine;
+                    break;
+                case sawtooth:
+                    myWave = square;
+                    break;
+                default:
+                break;
+                }
+            }
+        
         }
         //do other tasks in main - interrupts will process button message characters
         myled = 1;