For MAX32630FTHR Demo Board: Plays piano notes mapped to keyboard keys interfaced through serial port (puTTY or powershell).
Dependencies: SDFileSystem max32630fthr USBDevice
Diff: main.cpp
- Revision:
- 2:93da96b41127
- Parent:
- 1:78ca0566c062
- Child:
- 3:3a4d2d10e298
--- a/main.cpp Tue Jul 16 02:07:49 2019 +0000 +++ b/main.cpp Tue Jul 16 09:37:41 2019 +0000 @@ -40,7 +40,7 @@ void placeNewSample(void) { - PWM.write(audioDataBuffer[bufferPOS++]*!Button); //multiply by POT value for volume. + PWM.write(audioDataBuffer[bufferPOS++]); //multiply by POT value for volume. bufferPOS = (bufferPOS+1) & 0x07F; } @@ -49,7 +49,7 @@ WavFile Track; Ticker SampleTime; - daplink.printf("\f---DAPLINK SERIAL PORT---\r\n\r\nPLAY TONE VER 26 \r\n (CHANGEABLE TONE) MAX FREQUENCY: 1680. \r\n AFTER 1680Hz INPUTS CANNOT BE PROCESSED.\r\n\r\n"); + daplink.printf("\f---DAPLINK SERIAL PORT---\r\n\r\nMINI PIANO ver 1 \r\nMAKE SURE YOUR PUTTY IS SET TO NOT WAIT FOR [ENTER] \r\nMIDDLE A (A4) (440Hz) IS Y, [WHITE] KEYS VALID FROM 1 to L. \r\nPRESS SHIFT FOR SHARP\r\n\r\n"); microUSB.printf("micro USB serial port\r\n"); rLED = LED_ON; wait_ms(500); @@ -68,7 +68,7 @@ printf("Playing tone...\r\n"); - int PlayingFreq = 500; + int PlayingFreq = 440, attached = 0; while(1) { @@ -81,22 +81,183 @@ printf("\r\nTicker Period: %f\tTicker Freq: %f\r\nTarget Freq: %i\r\n\r\n",ticker_period, 1/ticker_period, PlayingFreq); - SampleTime.attach(&placeNewSample,ticker_period); + if(attached) + { + SampleTime.attach(&placeNewSample,ticker_period); + } + bLED = LED_OFF; char c; - char number[10]; - for(i=0;i<10 && c != '\r' && c != '\n'; i++) + c = daplink.getc(); + + gLED = LED_ON; + + switch(c) { - c = daplink.getc(); - number[i] = c; + case '1': + PlayingFreq = 98; + break; + case '!': + PlayingFreq = 404; + break; + case '2': + PlayingFreq = 110; + break; + case '@': + PlayingFreq = 117; + break; + case '3': + PlayingFreq = 123; + break; + case '4': + PlayingFreq = 131; + break; + case '$': + PlayingFreq = 139; + break; + case '5': + PlayingFreq = 147; + break; + case '%': + PlayingFreq = 156; + break; + case '6': + PlayingFreq = 165; + break; + case '7': + PlayingFreq = 175; + break; + case '&': + PlayingFreq = 185; + break; + case '8': + PlayingFreq = 196; + break; + case '*': + PlayingFreq = 208; + break; + case '9': + PlayingFreq = 220; + break; + case '(': + PlayingFreq = 233; + break; + case '0': + PlayingFreq = 247; + break; + case 'q': + PlayingFreq = 262; + break; + case 'Q': + PlayingFreq = 277; + break; + case 'w': + PlayingFreq = 294; + break; + case 'W': + PlayingFreq = 311; + break; + case 'e': + PlayingFreq = 330; + break; + case 'r': + PlayingFreq = 349; + break; + case 'R': + PlayingFreq = 370; + break; + case 't': + PlayingFreq = 392; + break; + case 'T': + PlayingFreq = 415; + break; + case 'y': + PlayingFreq = 440; + break; + case 'Y': + PlayingFreq = 466; + break; + case 'u': + PlayingFreq = 494; + break; + case 'i': + PlayingFreq = 523; + break; + case 'I': + PlayingFreq = 554; + break; + case 'o': + PlayingFreq = 587; + break; + case 'O': + PlayingFreq = 622; + break; + case 'p': + PlayingFreq = 659; + break; + case 'a': + PlayingFreq = 698; + break; + case 'A': + PlayingFreq = 740; + break; + case 's': + PlayingFreq = 784; + break; + case 'S': + PlayingFreq = 831; + break; + case 'd': + PlayingFreq = 880; + break; + case 'D': + PlayingFreq = 932; + break; + case 'f': + PlayingFreq = 988; + break; + case 'g': + PlayingFreq = 1047; + break; + case 'G': + PlayingFreq = 1109; + break; + case 'h': + PlayingFreq = 1175; + break; + case 'H': + PlayingFreq = 1245; + break; + case 'j': + PlayingFreq = 1319; + break; + case 'k': + PlayingFreq = 1397; + break; + case 'K': + PlayingFreq = 1480; + break; + case 'l': + PlayingFreq = 1568; + break; + case 'L': + PlayingFreq = 1661; + break; + case '\r': + attached = !attached; + break; + } + + gLED = LED_OFF; + rLED = !rLED; + if(attached) + { + SampleTime.detach(); } - gLED = LED_ON; - PlayingFreq = strtol(number,NULL,0); - gLED = LED_OFF; - rLED = !rLED; - SampleTime.detach(); + printf("\033[A\033[A\033[A\033[A"); } };