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