
Bluetooth Enabled Keyboard/Synthesizer for mbed
Dependencies: mbed 4DGL-uLCD-SE SDFileSystem mbed-rtos
Diff: main.cpp
- Revision:
- 0:48311ffdfa96
- Child:
- 1:830a669cacbe
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Apr 15 21:14:34 2016 +0000 @@ -0,0 +1,80 @@ +#include "mbed.h" +Serial Blue(p28,p27); +Serial PC(USBTX,USBRX); +DigitalOut myled(LED1); +DigitalOut myled4(LED4); + +//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() +{ + keyPress = Blue.getc(); + PC.putc(keyPress); + readyFlag = true; + PC.printf("\n\r Value of readyFlag is: %i",readyFlag); + + //PC.printf("Value of keyPress is: %c\n\r",keyPress); +} + +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 + { + PC.printf("Got an Z"); + readyFlag = false; + // Play note that corresponds to Z + } + else if((keyPress =='X') && (readyFlag)) // button X pressed + { + PC.printf("Got an X"); + // Play note that corresponds to X + } + else if((keyPress =='C' && (readyFlag)){} // button C pressed + // Play note that corresponds to C + else if((keyPress =='V') && (readyFlag)){} // button V pressed + // Play note that corresponds to V + else if((keyPress =='B') && (readyFlag)){} // button B pressed + // Play note that corresponds to B + else if((keyPress =='N') && (readyFlag)){} // button N pressed + // Play note that corresponds to N + else if((keyPress =='M') && (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 + // Raise an octave + else if((keyPress =='Q') && (readyFlag)){} // button Q pressed + // Raise Attack Value + else if((keyPress =='A') && (readyFlag)){} // button A pressed + // Lower Attack Value + else if((keyPress =='W') && (readyFlag)){} // button W pressed + // Raise Delay Value + else if((keyPress =='S') && (readyFlag)){} // button S pressed + // Lower Delay Value + else if((keyPress =='E') && (readyFlag)){} // button E pressed + // Raise Sustain Value + else if((keyPress =='D') && (readyFlag)){} // button D pressed + // Lower Sustain Value + else if((keyPress =='R') && (readyFlag)){} // button R pressed + // Raise Release Value + else if((keyPress =='F') && (readyFlag)){} // button F pressed + // Lower Release Value + } + //do other tasks in main - interrupts will process button message characters + myled = 1; + wait(0.1); + myled = 0; + wait(0.1); + +}