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@12:60c531df03fd, 2016-10-12 (annotated)
- Committer:
- garphil
- Date:
- Wed Oct 12 10:55:59 2016 +0000
- Revision:
- 12:60c531df03fd
- Parent:
- 11:c0728c05f977
- Child:
- 13:3b05cd187c41
- Child:
- 14:839ab5f50d40
With BT
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garphil | 1:ab4c9a0a5374 | 1 | #include "LaLaBox.h" |
garphil | 9:6b8118063819 | 2 | Serial pc_uart(PA_2, PA_3); |
garphil | 12:60c531df03fd | 3 | Serial bt_uart(PA_9, PA_10); |
garphil | 1:ab4c9a0a5374 | 4 | |
garphil | 1:ab4c9a0a5374 | 5 | // ---------------- Local global variables -------------- |
garphil | 1:ab4c9a0a5374 | 6 | |
garphil | 1:ab4c9a0a5374 | 7 | // --- Sound --- |
garphil | 6:2f4867594333 | 8 | 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 | 6:2f4867594333 | 9 | 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 | 10 | 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 | 11 | Music song_xfile("Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b."); |
garphil | 6:2f4867594333 | 12 | 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 | 13 | |
garphil | 2:050f12806bc5 | 14 | // ---------------- PIN DEFINITIONS --------------------- |
garphil | 2:050f12806bc5 | 15 | DigitalOut myled(LED1); // Blinking LED |
garphil | 5:f62e799558c3 | 16 | InterruptIn myButton(USER_BUTTON); |
garphil | 11:c0728c05f977 | 17 | InterruptIn buttonBox(PB_9); |
garphil | 2:050f12806bc5 | 18 | |
garphil | 6:2f4867594333 | 19 | // --- Define the Four PINs & Time of movement used for Motor drive ----- |
garphil | 11:c0728c05f977 | 20 | Motor motorBox(PA_6, PA_7, PB_6, PC_7, 20000); |
garphil | 11:c0728c05f977 | 21 | Motor motorDancer(PA_4,PB_0,PC_1,PC_0, 10000); |
garphil | 11:c0728c05f977 | 22 | |
garphil | 11:c0728c05f977 | 23 | |
garphil | 6:2f4867594333 | 24 | |
garphil | 6:2f4867594333 | 25 | // PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW |
garphil | 11:c0728c05f977 | 26 | LED_WS2812 ledBand(D3,16); |
garphil | 2:050f12806bc5 | 27 | |
garphil | 1:ab4c9a0a5374 | 28 | // --- Define PC_8 as the output of PWM use for Tones ----- |
garphil | 11:c0728c05f977 | 29 | Buzzer buzzer(PB_8); |
garphil | 0:30cb0f6dad87 | 30 | |
garphil | 1:ab4c9a0a5374 | 31 | Note la("A#4",50); //the sound |
garphil | 1:ab4c9a0a5374 | 32 | |
garphil | 5:f62e799558c3 | 33 | // init |
garphil | 6:2f4867594333 | 34 | int state = 0; |
garphil | 2:050f12806bc5 | 35 | |
garphil | 1:ab4c9a0a5374 | 36 | void help() // Display list of Commands |
garphil | 1:ab4c9a0a5374 | 37 | { |
garphil | 1:ab4c9a0a5374 | 38 | DEBUG("List of commands:\n\r"); |
garphil | 1:ab4c9a0a5374 | 39 | DEBUG(" h --> Help, display list of cammands\n\r"); |
garphil | 10:983ed805d74f | 40 | } |
garphil | 1:ab4c9a0a5374 | 41 | |
garphil | 11:c0728c05f977 | 42 | void clicked() { |
garphil | 11:c0728c05f977 | 43 | motorBox.Stop(); |
garphil | 11:c0728c05f977 | 44 | motorDancer.Stop(); |
garphil | 11:c0728c05f977 | 45 | ledBand.ResetColor(); |
garphil | 11:c0728c05f977 | 46 | } |
garphil | 11:c0728c05f977 | 47 | |
garphil | 5:f62e799558c3 | 48 | void pressed() { |
garphil | 6:2f4867594333 | 49 | state++; |
garphil | 6:2f4867594333 | 50 | switch(state) { |
garphil | 6:2f4867594333 | 51 | case 1: |
garphil | 11:c0728c05f977 | 52 | motorDancer.Stop(); |
garphil | 11:c0728c05f977 | 53 | motorBox.RunDegrees(COUNTERCLOCKWISE, (float)60.0); |
garphil | 11:c0728c05f977 | 54 | motorDancer.RunDegrees(COUNTERCLOCKWISE, 6*(float)360.0); |
garphil | 6:2f4867594333 | 55 | ledBand.SetColor(WHITE); |
garphil | 6:2f4867594333 | 56 | break; |
garphil | 6:2f4867594333 | 57 | case 2: |
garphil | 10:983ed805d74f | 58 | // motorDancer.RunDegrees(CLOCKWISE, (float)180.0); |
garphil | 11:c0728c05f977 | 59 | motorBox.RunDegrees(CLOCKWISE, (float)100.0); |
garphil | 7:592af6237038 | 60 | ledBand.SetColor(0x0000FF); |
garphil | 10:983ed805d74f | 61 | ledBand.SetIntensity(20.0); |
garphil | 6:2f4867594333 | 62 | break; |
garphil | 6:2f4867594333 | 63 | case 3: |
garphil | 7:592af6237038 | 64 | ledBand.InsertColor(BLUE); |
garphil | 10:983ed805d74f | 65 | ledBand.InsertColor(WHITE); |
garphil | 7:592af6237038 | 66 | ledBand.InsertColor(RED); |
garphil | 6:2f4867594333 | 67 | break; |
garphil | 7:592af6237038 | 68 | case 4: |
garphil | 7:592af6237038 | 69 | ledBand.StartRotation(1); |
garphil | 6:2f4867594333 | 70 | break; |
garphil | 6:2f4867594333 | 71 | case 5: |
garphil | 7:592af6237038 | 72 | ledBand.StopRotation(); |
garphil | 10:983ed805d74f | 73 | ledBand.ResetColor(); |
garphil | 10:983ed805d74f | 74 | ledBand.InsertColorNtimes(3,BLUE,20.0); |
garphil | 7:592af6237038 | 75 | ledBand.InsertColorNtimes(1,WHITE); |
garphil | 10:983ed805d74f | 76 | ledBand.InsertColorNtimes(4,RED,50.0); |
garphil | 9:6b8118063819 | 77 | ledBand.StartRotation(0.1); |
garphil | 11:c0728c05f977 | 78 | // PLAY_MUSIC(song_happy_birthday, buzzer); |
garphil | 6:2f4867594333 | 79 | break; |
garphil | 6:2f4867594333 | 80 | default: |
garphil | 7:592af6237038 | 81 | ledBand.StopRotation(); |
garphil | 10:983ed805d74f | 82 | // motorDancer.Stop(); |
garphil | 10:983ed805d74f | 83 | // motorBox.Stop(); |
garphil | 6:2f4867594333 | 84 | state = 0; |
garphil | 7:592af6237038 | 85 | break; |
garphil | 5:f62e799558c3 | 86 | } |
garphil | 9:6b8118063819 | 87 | myled = !myled; // To see something is alive |
garphil | 7:592af6237038 | 88 | |
garphil | 5:f62e799558c3 | 89 | } |
garphil | 5:f62e799558c3 | 90 | |
garphil | 10:983ed805d74f | 91 | |
garphil | 10:983ed805d74f | 92 | |
garphil | 11:c0728c05f977 | 93 | |
garphil | 0:30cb0f6dad87 | 94 | int main() { |
garphil | 1:ab4c9a0a5374 | 95 | myled = 1; // To see something is alive |
garphil | 11:c0728c05f977 | 96 | bool flaghelp; |
garphil | 10:983ed805d74f | 97 | DEBUG("\n\n%d\r",SystemCoreClock); |
garphil | 1:ab4c9a0a5374 | 98 | DEBUG("------------------------------------------\n\r"); |
garphil | 8:fb28b9ec6d6e | 99 | DEBUG("----- LaLaBox (CreaLab) version 1.0 ----\n\r"); |
garphil | 1:ab4c9a0a5374 | 100 | DEBUG("------------------------------------------\n\r"); |
garphil | 12:60c531df03fd | 101 | // help(); |
garphil | 1:ab4c9a0a5374 | 102 | DEBUG("------------------------------------------\n\r"); |
garphil | 10:983ed805d74f | 103 | ledBand.SetColor(BLACK); |
garphil | 12:60c531df03fd | 104 | DEBUG("SystemCoreClock = %d Hz =\n\r", SystemCoreClock); |
garphil | 10:983ed805d74f | 105 | |
garphil | 11:c0728c05f977 | 106 | CATCH_BUTTON(myButton,clicked); |
garphil | 11:c0728c05f977 | 107 | CATCH_BUTTON(buttonBox,clicked); |
garphil | 11:c0728c05f977 | 108 | buttonBox.mode(PullUp); |
garphil | 11:c0728c05f977 | 109 | buttonBox.rise(&clicked); |
garphil | 6:2f4867594333 | 110 | |
garphil | 10:983ed805d74f | 111 | // PLAY_NOTE(la, buzzer); |
garphil | 12:60c531df03fd | 112 | DEBUG("Wait 2s\n\r", SystemCoreClock); |
garphil | 9:6b8118063819 | 113 | |
garphil | 6:2f4867594333 | 114 | wait(2); // Some delay |
garphil | 1:ab4c9a0a5374 | 115 | myled = 0; // Real stuff starts here |
garphil | 12:60c531df03fd | 116 | DEBUG("Enter a command : \n\r", SystemCoreClock); |
garphil | 11:c0728c05f977 | 117 | |
garphil | 5:f62e799558c3 | 118 | while(1) { |
garphil | 1:ab4c9a0a5374 | 119 | char command; // Command to execute |
garphil | 5:f62e799558c3 | 120 | DEBUG(">> "); |
garphil | 12:60c531df03fd | 121 | command = bt_uart.getc(); |
garphil | 1:ab4c9a0a5374 | 122 | DEBUG("%c", command); |
garphil | 11:c0728c05f977 | 123 | flaghelp = false; |
garphil | 1:ab4c9a0a5374 | 124 | switch (command) { |
garphil | 11:c0728c05f977 | 125 | case 'h': |
garphil | 12:60c531df03fd | 126 | help(); |
garphil | 11:c0728c05f977 | 127 | flaghelp=true; |
garphil | 11:c0728c05f977 | 128 | CASE('o', "OpenBox", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)60.0); ) |
garphil | 11:c0728c05f977 | 129 | CASE('c', "CloseBox", motorBox.RunDegrees(CLOCKWISE, (float)60.0); ) |
garphil | 11:c0728c05f977 | 130 | CASE('d', "1 step OpenBox ", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)1.0); ) |
garphil | 11:c0728c05f977 | 131 | CASE('e', "1 step CloseBox ", motorBox.RunDegrees(CLOCKWISE, (float)1.0); ) |
garphil | 11:c0728c05f977 | 132 | CASE('f', "Dancer Clock Wise ", motorDancer.RunInfinite(CLOCKWISE); ) |
garphil | 11:c0728c05f977 | 133 | CASE('j', "Dancer Counter Clock Wise ", motorDancer.RunInfinite(COUNTERCLOCKWISE); ) |
garphil | 11:c0728c05f977 | 134 | CASE('s', "STOP ", clicked(); ) |
garphil | 12:60c531df03fd | 135 | CASE('m', "Music 1", PLAY_MUSIC(song_xfile,buzzer); ) |
garphil | 12:60c531df03fd | 136 | CASE('n', "Music 2", PLAY_MUSIC(song_lightmyfire,buzzer); ) |
garphil | 12:60c531df03fd | 137 | CASE('p', "Music 3", PLAY_MUSIC(song_greensleaves,buzzer); ) |
garphil | 12:60c531df03fd | 138 | CASE('q', "Music 4", PLAY_MUSIC(song_christmas,buzzer); ) |
garphil | 12:60c531df03fd | 139 | CASE('r', "Music 5", PLAY_MUSIC(song_happy_birthday,buzzer); ) |
garphil | 11:c0728c05f977 | 140 | CASE('l', "Light ", |
garphil | 11:c0728c05f977 | 141 | ledBand.StopRotation(); ledBand.ResetColor(); |
garphil | 11:c0728c05f977 | 142 | ledBand.InsertColorNtimes(3,BLUE,20.0); |
garphil | 11:c0728c05f977 | 143 | ledBand.InsertColorNtimes(1,WHITE); |
garphil | 11:c0728c05f977 | 144 | ledBand.InsertColorNtimes(4,RED,50.0); |
garphil | 11:c0728c05f977 | 145 | ledBand.StartRotation(0.1); |
garphil | 11:c0728c05f977 | 146 | ) |
garphil | 11:c0728c05f977 | 147 | |
garphil | 1:ab4c9a0a5374 | 148 | default : DEBUG("invalid command; use: 'h' for help()"); |
garphil | 1:ab4c9a0a5374 | 149 | } |
garphil | 0:30cb0f6dad87 | 150 | } |
garphil | 1:ab4c9a0a5374 | 151 | } |