
Bluetooth Enabled Keyboard/Synthesizer for mbed
Dependencies: mbed 4DGL-uLCD-SE SDFileSystem mbed-rtos
main.cpp
- Committer:
- jmpin
- Date:
- 2016-04-27
- Revision:
- 2:f06ba516b1ad
- Parent:
- 1:830a669cacbe
- Child:
- 3:3aba1d783730
File content as of revision 2:f06ba516b1ad:
#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 char keyPress; //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); } 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 == C_KEY) && (readyFlag))// button Z pressed { PC.printf("Got n Z"); readyFlag = false; // Play note that corresponds to Z } else if((keyPress == D_KEY) && (readyFlag)) // button X pressed { PC.printf("Got an X"); // Play note that corresponds to X } else if((keyPress == E_KEY && (readyFlag)){} // button C pressed // Play note that corresponds to C else if((keyPress == F_KEY) && (readyFlag)){} // button V pressed // Play note that corresponds to V else if((keyPress == G_KEY) && (readyFlag)){} // button B pressed // Play note that corresponds to B else if((keyPress == A_KEY) && (readyFlag)){} // button N pressed // Play note that corresponds to N else if((keyPress == B_KEY) && (readyFlag)){} // button M pressed // Play note that corresponds to M else if((keyPress == RAISE_OCTAVE_KEY) && (readyFlag)){ // button O pressed // Raise an octave 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 currentAttackVal++; } else if((keyPress == LOWER_ATTACK_KEY) && (readyFlag)){ // button A pressed // Lower Attack Value currentAttackVal--; } else if((keyPress == RAISE_DELAY_KEY) && (readyFlag)){ // button W pressed // Raise Delay Value currentDelayVal++; } else if((keyPress == LOWER_DELAY_KEY) && (readyFlag)){ // button S pressed // Lower Delay Value currentDelayVal--; } else if((keyPress == RAISE_SUSTAIN_KEY) && (readyFlag)){ // button E pressed // Raise Sustain Value currentSustainVal++; } else if((keyPress == LOWER_SUSTAIN_KEY) && (readyFlag)){ // button D pressed // Lower Sustain Value currentSustainVal--; } else if((keyPress == RAISE_RELEASE_KEY) && (readyFlag)){ // button R pressed // Raise Release Value 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; wait(0.1); myled = 0; wait(0.1); }