A MIDI piano synthesizer that implements the Karplus Strong physical modeling algorithm.

Dependencies:   mbed USBDevice PinDetect

Committer:
ndelfino
Date:
Mon Apr 11 18:21:37 2016 +0000
Revision:
4:bb9f50305401
Child:
5:a687cfa7be62
Added LEDController which will turn the lights on and off depending upon the keys being pressed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ndelfino 4:bb9f50305401 1 #include "mbed.h"
ndelfino 4:bb9f50305401 2
ndelfino 4:bb9f50305401 3 DigitalOut myled1_1(p5);
ndelfino 4:bb9f50305401 4 DigitalOut myled1_2(p6);
ndelfino 4:bb9f50305401 5 DigitalOut myled1_3(p7);
ndelfino 4:bb9f50305401 6
ndelfino 4:bb9f50305401 7 DigitalOut myled2_1(p8);
ndelfino 4:bb9f50305401 8 DigitalOut myled2_2(p9);
ndelfino 4:bb9f50305401 9 DigitalOut myled2_3(p10);
ndelfino 4:bb9f50305401 10
ndelfino 4:bb9f50305401 11 DigitalOut myled3_1(p11);
ndelfino 4:bb9f50305401 12 DigitalOut myled3_2(p12);
ndelfino 4:bb9f50305401 13 DigitalOut myled3_3(p13);
ndelfino 4:bb9f50305401 14
ndelfino 4:bb9f50305401 15 DigitalOut myled4_1(p14);
ndelfino 4:bb9f50305401 16 DigitalOut myled4_2(p15);
ndelfino 4:bb9f50305401 17 DigitalOut myled4_3(p16);
ndelfino 4:bb9f50305401 18
ndelfino 4:bb9f50305401 19
ndelfino 4:bb9f50305401 20 Serial pc(USBTX, USBRX);
ndelfino 4:bb9f50305401 21
ndelfino 4:bb9f50305401 22 //If the LED is -1 then it is not in use or free to use.
ndelfino 4:bb9f50305401 23 int myLed1 = -1;
ndelfino 4:bb9f50305401 24 int myLed2 = -1;
ndelfino 4:bb9f50305401 25 int myLed3 = -1;
ndelfino 4:bb9f50305401 26 int myLed4 = -1;
ndelfino 4:bb9f50305401 27
ndelfino 4:bb9f50305401 28 //These are the notes numbers and RGB values.
ndelfino 4:bb9f50305401 29 int noteC[] = {24,0,0,0};
ndelfino 4:bb9f50305401 30 int noteD[] = {26,1,0,0};
ndelfino 4:bb9f50305401 31 int noteE[] = {28,0,1,0};
ndelfino 4:bb9f50305401 32 int noteF[] = {30,0,0,1};
ndelfino 4:bb9f50305401 33 int noteG[] = {32,1,1,0};
ndelfino 4:bb9f50305401 34 int noteA[] = {34,0,1,1};
ndelfino 4:bb9f50305401 35 int noteB[] = {36,1,1,1};
ndelfino 4:bb9f50305401 36
ndelfino 4:bb9f50305401 37 //A larger array of all the notes to be iterated over.
ndelfino 4:bb9f50305401 38 int notes[] = {noteC, noteD, noteE, noteF, noteG, noteA, noteB};
ndelfino 4:bb9f50305401 39
ndelfino 4:bb9f50305401 40 const int notesSize = 7;
ndelfino 4:bb9f50305401 41
ndelfino 4:bb9f50305401 42 int main() {
ndelfino 4:bb9f50305401 43
ndelfino 4:bb9f50305401 44 while(1) {
ndelfino 4:bb9f50305401 45
ndelfino 4:bb9f50305401 46 }
ndelfino 4:bb9f50305401 47 }
ndelfino 4:bb9f50305401 48
ndelfino 4:bb9f50305401 49 void getNote(note, type){
ndelfino 4:bb9f50305401 50 for(int i = 0; i < notesSize; i++){
ndelfino 4:bb9f50305401 51 if(note % notes[i][0] == 0){
ndelfino 4:bb9f50305401 52 chooseLedForNote(notes[i], type,0);
ndelfino 4:bb9f50305401 53 }else if(note % notes[i][0] == 1){
ndelfino 4:bb9f50305401 54 chooseLedForNote(notes[i], type, 1);
ndelfino 4:bb9f50305401 55 }
ndelfino 4:bb9f50305401 56 }
ndelfino 4:bb9f50305401 57 }
ndelfino 4:bb9f50305401 58
ndelfino 4:bb9f50305401 59 //Chooses which LED to use based upon which are set or if they needed to be turned off.
ndelfino 4:bb9f50305401 60 void chooseLedForNote(note, type, signature){
ndelfino 4:bb9f50305401 61
ndelfino 4:bb9f50305401 62 //Determines if the LED is not set and therefore can be used.
ndelfino 4:bb9f50305401 63 //Or if it is in use by the same note being passed in which means it needs to be turned off.
ndelfino 4:bb9f50305401 64 if(myLed1 == -1 || myLed1 == note[0] || myLed1 == (note[0] + 1)){
ndelfino 4:bb9f50305401 65 setLedToNote(note, type, signature);
ndelfino 4:bb9f50305401 66 }else if(myLed2 == -1 || myLed2 == note[0] || myLed2 == (note[0] + 1)){
ndelfino 4:bb9f50305401 67 setLedToNote(note, type, signature);
ndelfino 4:bb9f50305401 68 }else if(myLed3 == -1 || myLed3 == note[0] || myLed3 == (note[0] + 1)){
ndelfino 4:bb9f50305401 69 setLedToNote(note, type, signature);
ndelfino 4:bb9f50305401 70 }else if(myLed4 == -1 || myLed4 == note[0] || myLed4 == (note[0] + 1)){
ndelfino 4:bb9f50305401 71 setLedToNote(note, type, signature);
ndelfino 4:bb9f50305401 72 }
ndelfino 4:bb9f50305401 73 }
ndelfino 4:bb9f50305401 74
ndelfino 4:bb9f50305401 75 //This sets the note or clears the previously set note if the type is off.
ndelfino 4:bb9f50305401 76 void setLedToNote(note, type, signature){
ndelfino 4:bb9f50305401 77 if(!(type == "off")){
ndelfino 4:bb9f50305401 78 myled1 = note[0];
ndelfino 4:bb9f50305401 79 myled1_1 = note[1];
ndelfino 4:bb9f50305401 80 myled1_2 = note[2];
ndelfino 4:bb9f50305401 81 myled1_3 = note[3];
ndelfino 4:bb9f50305401 82 }else{
ndelfino 4:bb9f50305401 83 myLed1 = -1;
ndelfino 4:bb9f50305401 84 myled1_1 = 0;
ndelfino 4:bb9f50305401 85 myled1_2 = 0;
ndelfino 4:bb9f50305401 86 myled1_3 = 0;
ndelfino 4:bb9f50305401 87 }
ndelfino 4:bb9f50305401 88 }