Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@18:92f4f2b44d6d, 2017-04-11 (annotated)
- Committer:
- garphil
- Date:
- Tue Apr 11 23:03:07 2017 +0000
- Revision:
- 18:92f4f2b44d6d
- Parent:
- 16:8ae70f0b8fca
- Child:
- 19:aa99c24e4ee0
Cancel previous commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fbd38 | 16:8ae70f0b8fca | 1 | /* |
fbd38 | 16:8ae70f0b8fca | 2 | * LaLaBOX program |
fbd38 | 16:8ae70f0b8fca | 3 | * |
fbd38 | 16:8ae70f0b8fca | 4 | * Version 2.0, March 12, 2017 |
fbd38 | 16:8ae70f0b8fca | 5 | * for Nucleo32: F303K8 |
fbd38 | 16:8ae70f0b8fca | 6 | * |
fbd38 | 16:8ae70f0b8fca | 7 | */ |
fbd38 | 16:8ae70f0b8fca | 8 | |
garphil | 14:839ab5f50d40 | 9 | #include "Crealab.h" |
garphil | 12:60c531df03fd | 10 | Serial bt_uart(PA_9, PA_10); |
garphil | 1:ab4c9a0a5374 | 11 | |
garphil | 1:ab4c9a0a5374 | 12 | // ---------------- Local global variables -------------- |
fbd38 | 16:8ae70f0b8fca | 13 | |
garphil | 1:ab4c9a0a5374 | 14 | // --- Sound --- |
garphil | 18:92f4f2b44d6d | 15 | /*Music song_happy_birthday("Happy Birthday Song:d=4,o=5,b=125:16c,32p,32c,32p,8d,32p,8c,32p,8f,32p,e,16p,16c,32p,32c,32p,8d,32p,8c,32p,8g,32p,f,8p,16c,32p,32c,32p,8c6,32p,8a,32p,8f,32p,8e,32p,8d,32p,16a#,32p,32a#,32p,8a,32p,8f,32p,8g,32p,f"); |
garphil | 18:92f4f2b44d6d | 16 | Music song_greensleaves("Greensleaves:d=4,o=5,b=140:g,2a#,c6,d.6,8d#6,d6,2c6,a,f.,8g,a,2a#,g,g.,8f,g,2a,f,2d,g,2a#,c6,d.6,8e6,d6,2c6,a,f.,8g,a,a#.,8a,g,f#.,8e,f#,2g"); |
garphil | 18:92f4f2b44d6d | 17 | Music song_lightmyfire("LightMyFire:d=4,o=5,b=140:8b,16g,16a,8b,8d6,8c6,8b,8a,8g,8a,16f,16a,8c6,8f6,16d6,16c6,16a#,16g,8g#,8g,8g#,16g,16a,8b,8c#6,16b,16a,16g,16f,8e,8f,1a,a"); |
garphil | 18:92f4f2b44d6d | 18 | Music song_xfile("Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b."); |
garphil | 18:92f4f2b44d6d | 19 | Music song_christmas("Christmas:d=4,o=5,b=100:f#,g#,2a#,2a#,d#.,8f,f,f,2f#,2d#,2f#.6,f#,#g,8g#,g#,8a#,b,8c#,c#,2c#,8d#,8f.,8f#.,8f.,d#,f,2f#.,a#,8b.,8b.,8b.,d#,f,2c#.,a#,8b.,8b.,8b.,d#,f,f#,p,g#,g#,g#,8g#,8a#,8g#,f#.,g#,a#,p,c,c,c,8c,8c#,8c,a#.,c,c#,a#,b,a#,a,a#,b,c,"); |
garphil | 18:92f4f2b44d6d | 20 | */ |
garphil | 18:92f4f2b44d6d | 21 | const char song_happy_birthday[]="Happy Birthday Song:d=4,o=5,b=125:16c,32p,32c,32p,8d,32p,8c,32p,8f,32p,e,16p,16c,32p,32c,32p,8d,32p,8c,32p,8g,32p,f,8p,16c,32p,32c,32p,8c6,32p,8a,32p,8f,32p,8e,32p,8d,32p,16a#,32p,32a#,32p,8a,32p,8f,32p,8g,32p,f"; |
garphil | 6:2f4867594333 | 22 | Music song_greensleaves("Greensleaves:d=4,o=5,b=140:g,2a#,c6,d.6,8d#6,d6,2c6,a,f.,8g,a,2a#,g,g.,8f,g,2a,f,2d,g,2a#,c6,d.6,8e6,d6,2c6,a,f.,8g,a,a#.,8a,g,f#.,8e,f#,2g"); |
garphil | 6:2f4867594333 | 23 | Music song_lightmyfire("LightMyFire:d=4,o=5,b=140:8b,16g,16a,8b,8d6,8c6,8b,8a,8g,8a,16f,16a,8c6,8f6,16d6,16c6,16a#,16g,8g#,8g,8g#,16g,16a,8b,8c#6,16b,16a,16g,16f,8e,8f,1a,a"); |
garphil | 6:2f4867594333 | 24 | Music song_xfile("Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b."); |
garphil | 6:2f4867594333 | 25 | Music song_christmas("Christmas:d=4,o=5,b=100:f#,g#,2a#,2a#,d#.,8f,f,f,2f#,2d#,2f#.6,f#,#g,8g#,g#,8a#,b,8c#,c#,2c#,8d#,8f.,8f#.,8f.,d#,f,2f#.,a#,8b.,8b.,8b.,d#,f,2c#.,a#,8b.,8b.,8b.,d#,f,f#,p,g#,g#,g#,8g#,8a#,8g#,f#.,g#,a#,p,c,c,c,8c,8c#,8c,a#.,c,c#,a#,b,a#,a,a#,b,c,"); |
garphil | 1:ab4c9a0a5374 | 26 | |
garphil | 2:050f12806bc5 | 27 | // ---------------- PIN DEFINITIONS --------------------- |
garphil | 2:050f12806bc5 | 28 | DigitalOut myled(LED1); // Blinking LED |
garphil | 18:92f4f2b44d6d | 29 | InterruptIn buttonBox(PB_1); |
garphil | 2:050f12806bc5 | 30 | |
garphil | 6:2f4867594333 | 31 | // --- Define the Four PINs & Time of movement used for Motor drive ----- |
fbd38 | 16:8ae70f0b8fca | 32 | Motor motorBox(PA_8, PA_11, PB_5, PB_4, 5000); |
fbd38 | 16:8ae70f0b8fca | 33 | Motor motorDancer(PA_4, PA_3, PA_1, PA_0, 2000); |
garphil | 6:2f4867594333 | 34 | |
garphil | 6:2f4867594333 | 35 | // PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW |
fbd38 | 16:8ae70f0b8fca | 36 | LED_WS2812 ledBand(PB_3,16); |
garphil | 2:050f12806bc5 | 37 | |
fbd38 | 16:8ae70f0b8fca | 38 | // --- Define PB_0 as the output of PWM use for Tones ----- |
fbd38 | 16:8ae70f0b8fca | 39 | Buzzer buzzer(PB_0); |
garphil | 18:92f4f2b44d6d | 40 | MusicStatic myMusic(&buzzer); |
garphil | 0:30cb0f6dad87 | 41 | |
garphil | 18:92f4f2b44d6d | 42 | //Note la("A#4",50); //the sound |
garphil | 1:ab4c9a0a5374 | 43 | |
garphil | 1:ab4c9a0a5374 | 44 | void help() // Display list of Commands |
garphil | 1:ab4c9a0a5374 | 45 | { |
garphil | 1:ab4c9a0a5374 | 46 | DEBUG("List of commands:\n\r"); |
garphil | 1:ab4c9a0a5374 | 47 | DEBUG(" h --> Help, display list of cammands\n\r"); |
fbd38 | 16:8ae70f0b8fca | 48 | } |
garphil | 1:ab4c9a0a5374 | 49 | |
fbd38 | 16:8ae70f0b8fca | 50 | /* Stop all processes */ |
fbd38 | 16:8ae70f0b8fca | 51 | void stop_all() |
fbd38 | 16:8ae70f0b8fca | 52 | { |
garphil | 11:c0728c05f977 | 53 | motorBox.Stop(); |
garphil | 11:c0728c05f977 | 54 | motorDancer.Stop(); |
garphil | 11:c0728c05f977 | 55 | ledBand.ResetColor(); |
garphil | 14:839ab5f50d40 | 56 | buzzer.stopPlay(); |
garphil | 11:c0728c05f977 | 57 | } |
garphil | 11:c0728c05f977 | 58 | |
fbd38 | 16:8ae70f0b8fca | 59 | /* Interrupt routine, switch of end of course */ |
fbd38 | 16:8ae70f0b8fca | 60 | void clicked() |
fbd38 | 16:8ae70f0b8fca | 61 | { |
fbd38 | 16:8ae70f0b8fca | 62 | DEBUG("End of Course\n\r"); |
fbd38 | 16:8ae70f0b8fca | 63 | stop_all(); |
garphil | 5:f62e799558c3 | 64 | } |
garphil | 5:f62e799558c3 | 65 | |
fbd38 | 16:8ae70f0b8fca | 66 | /* Main Routine */ |
fbd38 | 16:8ae70f0b8fca | 67 | int main() |
fbd38 | 16:8ae70f0b8fca | 68 | { |
garphil | 1:ab4c9a0a5374 | 69 | myled = 1; // To see something is alive |
garphil | 11:c0728c05f977 | 70 | bool flaghelp; |
fbd38 | 16:8ae70f0b8fca | 71 | DEBUG("------------------------------------------\n\r"); |
fbd38 | 16:8ae70f0b8fca | 72 | DEBUG("----- LaLaBox (CreaLab) version 2.0 ----\n\r"); |
fbd38 | 16:8ae70f0b8fca | 73 | DEBUG("------------------------------------------\n\r"); |
fbd38 | 16:8ae70f0b8fca | 74 | ledBand.SetColor(WHITE); |
fbd38 | 16:8ae70f0b8fca | 75 | DEBUG("SystemCoreClock = %d Hz =\n\r", SystemCoreClock); |
fbd38 | 16:8ae70f0b8fca | 76 | DEBUG("Wait 2s\n\r"); |
garphil | 10:983ed805d74f | 77 | |
fbd38 | 16:8ae70f0b8fca | 78 | /* Connect EoC button */ |
fbd38 | 16:8ae70f0b8fca | 79 | CATCH_BUTTON(buttonBox,clicked); |
fbd38 | 16:8ae70f0b8fca | 80 | buttonBox.mode(PullUp); |
fbd38 | 16:8ae70f0b8fca | 81 | buttonBox.fall(&clicked); |
fbd38 | 16:8ae70f0b8fca | 82 | |
fbd38 | 16:8ae70f0b8fca | 83 | /* Play a tone */ |
garphil | 18:92f4f2b44d6d | 84 | // PLAY_NOTE(la, buzzer); |
garphil | 9:6b8118063819 | 85 | |
garphil | 6:2f4867594333 | 86 | wait(2); // Some delay |
garphil | 1:ab4c9a0a5374 | 87 | myled = 0; // Real stuff starts here |
fbd38 | 16:8ae70f0b8fca | 88 | ledBand.SetColor(BLACK); |
fbd38 | 16:8ae70f0b8fca | 89 | DEBUG("Enter a command : \n\r"); |
garphil | 18:92f4f2b44d6d | 90 | myMusic.play(song_happy_birthday); |
garphil | 18:92f4f2b44d6d | 91 | // song_greensleaves.play(&buzzer); |
fbd38 | 16:8ae70f0b8fca | 92 | while(1) { |
garphil | 1:ab4c9a0a5374 | 93 | char command; // Command to execute |
garphil | 5:f62e799558c3 | 94 | DEBUG(">> "); |
garphil | 12:60c531df03fd | 95 | command = bt_uart.getc(); |
garphil | 1:ab4c9a0a5374 | 96 | DEBUG("%c", command); |
garphil | 11:c0728c05f977 | 97 | flaghelp = false; |
garphil | 1:ab4c9a0a5374 | 98 | switch (command) { |
fbd38 | 16:8ae70f0b8fca | 99 | case 'h': |
fbd38 | 16:8ae70f0b8fca | 100 | help(); |
fbd38 | 16:8ae70f0b8fca | 101 | flaghelp=true; |
fbd38 | 16:8ae70f0b8fca | 102 | CASE('o', "OpenBox", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)140.0); ) |
fbd38 | 16:8ae70f0b8fca | 103 | CASE('c', "CloseBox", motorBox.RunDegrees(CLOCKWISE, (float)140.0); ) |
fbd38 | 16:8ae70f0b8fca | 104 | CASE('d', "1 step OpenBox ", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)1.0); ) |
fbd38 | 16:8ae70f0b8fca | 105 | CASE('e', "1 step CloseBox ", motorBox.RunDegrees(CLOCKWISE, (float)1.0); ) |
fbd38 | 16:8ae70f0b8fca | 106 | CASE('f', "Dancer Clock Wise ", motorDancer.RunInfinite(CLOCKWISE); ) |
fbd38 | 16:8ae70f0b8fca | 107 | CASE('j', "Dancer Counter Clock Wise ", motorDancer.RunInfinite(COUNTERCLOCKWISE); ) |
fbd38 | 16:8ae70f0b8fca | 108 | CASE('s', "STOP ", stop_all(); ) |
garphil | 18:92f4f2b44d6d | 109 | // CASE('m', "Music 1", PLAY_MUSIC(song_xfile,buzzer); ) |
garphil | 18:92f4f2b44d6d | 110 | // CASE('n', "Music 2", PLAY_MUSIC(song_lightmyfire,buzzer); ) |
garphil | 18:92f4f2b44d6d | 111 | // CASE('p', "Music 3", PLAY_MUSIC(song_greensleaves,buzzer); ) |
garphil | 18:92f4f2b44d6d | 112 | // CASE('q', "Music 4", PLAY_MUSIC(song_christmas,buzzer); ) |
garphil | 18:92f4f2b44d6d | 113 | // CASE('r', "Music 5", PLAY_MUSIC(song_happy_birthday,buzzer); ) |
fbd38 | 16:8ae70f0b8fca | 114 | CASE('l', "Light ", |
fbd38 | 16:8ae70f0b8fca | 115 | ledBand.StopRotation(); ledBand.ResetColor(); |
fbd38 | 16:8ae70f0b8fca | 116 | ledBand.InsertColorNtimes(3,YELLOW,5.0); |
fbd38 | 16:8ae70f0b8fca | 117 | ledBand.InsertColorNtimes(1,PURPLE,5); |
fbd38 | 16:8ae70f0b8fca | 118 | ledBand.InsertColorNtimes(4,GREEN,10.0); |
fbd38 | 16:8ae70f0b8fca | 119 | ledBand.StartRotation(0.1); |
fbd38 | 16:8ae70f0b8fca | 120 | ) |
fbd38 | 16:8ae70f0b8fca | 121 | |
fbd38 | 16:8ae70f0b8fca | 122 | default : |
fbd38 | 16:8ae70f0b8fca | 123 | DEBUG("invalid command; use: 'h' for help()"); |
garphil | 1:ab4c9a0a5374 | 124 | } |
garphil | 0:30cb0f6dad87 | 125 | } |
garphil | 1:ab4c9a0a5374 | 126 | } |