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.
Diff: main.cpp
- Revision:
- 16:8ae70f0b8fca
- Parent:
- 14:839ab5f50d40
- Child:
- 17:04c9b524dd94
- Child:
- 18:92f4f2b44d6d
diff -r fa9496a23e1c -r 8ae70f0b8fca main.cpp --- a/main.cpp Fri Mar 03 11:50:35 2017 +0000 +++ b/main.cpp Sun Mar 12 17:09:48 2017 +0000 @@ -1,9 +1,16 @@ +/* + * LaLaBOX program + * + * Version 2.0, March 12, 2017 + * for Nucleo32: F303K8 + * + */ + #include "Crealab.h" -Serial pc_uart(PA_2, PA_3); Serial bt_uart(PA_9, PA_10); // ---------------- Local global variables -------------- - + // --- Sound --- 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"); 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"); @@ -13,141 +20,99 @@ // ---------------- PIN DEFINITIONS --------------------- DigitalOut myled(LED1); // Blinking LED -InterruptIn myButton(USER_BUTTON); -InterruptIn buttonBox(PB_9); +InterruptIn buttonBox(PB_1); // --- Define the Four PINs & Time of movement used for Motor drive ----- - Motor motorBox(PA_6, PA_7, PB_6, PC_7, 20000); - Motor motorDancer(PA_4,PB_0,PC_1,PC_0, 10000); - - +Motor motorBox(PA_8, PA_11, PB_5, PB_4, 5000); +Motor motorDancer(PA_4, PA_3, PA_1, PA_0, 2000); // PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW -LED_WS2812 ledBand(D3,16); +LED_WS2812 ledBand(PB_3,16); -// --- Define PC_8 as the output of PWM use for Tones ----- - Buzzer buzzer(PB_8); +// --- Define PB_0 as the output of PWM use for Tones ----- +Buzzer buzzer(PB_0); Note la("A#4",50); //the sound -// init -int state = 0; - void help() // Display list of Commands { DEBUG("List of commands:\n\r"); DEBUG(" h --> Help, display list of cammands\n\r"); - } +} -void clicked() { +/* Stop all processes */ +void stop_all() +{ motorBox.Stop(); motorDancer.Stop(); ledBand.ResetColor(); buzzer.stopPlay(); } -void pressed() { - state++; - switch(state) { - case 1: - motorDancer.Stop(); - motorBox.RunDegrees(COUNTERCLOCKWISE, (float)60.0); - motorDancer.RunDegrees(COUNTERCLOCKWISE, 6*(float)360.0); - ledBand.SetColor(WHITE); - break; - case 2: -// motorDancer.RunDegrees(CLOCKWISE, (float)180.0); - motorBox.RunDegrees(CLOCKWISE, (float)100.0); - ledBand.SetColor(0x0000FF); - ledBand.SetIntensity(20.0); - break; - case 3: - ledBand.InsertColor(BLUE); - ledBand.InsertColor(WHITE); - ledBand.InsertColor(RED); - break; - case 4: - ledBand.StartRotation(1); - break; - case 5: - ledBand.StopRotation(); - ledBand.ResetColor(); - ledBand.InsertColorNtimes(3,BLUE,20.0); - ledBand.InsertColorNtimes(1,WHITE,20.0); - ledBand.InsertColorNtimes(4,RED,20.0); - ledBand.StartRotation(0.1); - // PLAY_MUSIC(song_happy_birthday, buzzer); - break; - default: - ledBand.StopRotation(); - // motorDancer.Stop(); - // motorBox.Stop(); - state = 0; - break; - } - myled = !myled; // To see something is alive - +/* Interrupt routine, switch of end of course */ +void clicked() +{ + DEBUG("End of Course\n\r"); + stop_all(); } - - - -int main() { +/* Main Routine */ +int main() +{ myled = 1; // To see something is alive bool flaghelp; - DEBUG("\n\n%d\r",SystemCoreClock); - DEBUG("------------------------------------------\n\r"); - DEBUG("----- LaLaBox (CreaLab) version 1.0 ----\n\r"); - DEBUG("------------------------------------------\n\r"); - // help(); - DEBUG("------------------------------------------\n\r"); - ledBand.SetColor(BLACK); - DEBUG("SystemCoreClock = %d Hz =\n\r", SystemCoreClock); + DEBUG("------------------------------------------\n\r"); + DEBUG("----- LaLaBox (CreaLab) version 2.0 ----\n\r"); + DEBUG("------------------------------------------\n\r"); + ledBand.SetColor(WHITE); + DEBUG("SystemCoreClock = %d Hz =\n\r", SystemCoreClock); + DEBUG("Wait 2s\n\r"); - CATCH_BUTTON(myButton,clicked); - CATCH_BUTTON(buttonBox,clicked); - buttonBox.mode(PullUp); - buttonBox.rise(&clicked); - - // PLAY_NOTE(la, buzzer); - DEBUG("Wait 2s\n\r", SystemCoreClock); + /* Connect EoC button */ + CATCH_BUTTON(buttonBox,clicked); + buttonBox.mode(PullUp); + buttonBox.fall(&clicked); + + /* Play a tone */ + PLAY_NOTE(la, buzzer); wait(2); // Some delay myled = 0; // Real stuff starts here - DEBUG("Enter a command : \n\r", SystemCoreClock); - ledBand.SetColor(WHITE); + ledBand.SetColor(BLACK); + DEBUG("Enter a command : \n\r"); - while(1) { + while(1) { char command; // Command to execute DEBUG(">> "); command = bt_uart.getc(); DEBUG("%c", command); flaghelp = false; switch (command) { - case 'h': - help(); - flaghelp=true; - CASE('o', "OpenBox", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)60.0); ) - CASE('c', "CloseBox", motorBox.RunDegrees(CLOCKWISE, (float)60.0); ) - CASE('d', "1 step OpenBox ", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)1.0); ) - CASE('e', "1 step CloseBox ", motorBox.RunDegrees(CLOCKWISE, (float)1.0); ) - CASE('f', "Dancer Clock Wise ", motorDancer.RunInfinite(CLOCKWISE); ) - CASE('j', "Dancer Counter Clock Wise ", motorDancer.RunInfinite(COUNTERCLOCKWISE); ) - CASE('s', "STOP ", clicked(); ) - CASE('m', "Music 1", PLAY_MUSIC(song_xfile,buzzer); ) - CASE('n', "Music 2", PLAY_MUSIC(song_lightmyfire,buzzer); ) - CASE('p', "Music 3", PLAY_MUSIC(song_greensleaves,buzzer); ) - CASE('q', "Music 4", PLAY_MUSIC(song_christmas,buzzer); ) - CASE('r', "Music 5", PLAY_MUSIC(song_happy_birthday,buzzer); ) - CASE('l', "Light ", - ledBand.StopRotation(); ledBand.ResetColor(); - ledBand.InsertColorNtimes(3,YELLOW,5.0); - ledBand.InsertColorNtimes(1,PURPLE,5); - ledBand.InsertColorNtimes(4,GREEN,10.0); - ledBand.StartRotation(0.1); - ) - - default : DEBUG("invalid command; use: 'h' for help()"); + case 'h': + help(); + flaghelp=true; + CASE('o', "OpenBox", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)140.0); ) + CASE('c', "CloseBox", motorBox.RunDegrees(CLOCKWISE, (float)140.0); ) + CASE('d', "1 step OpenBox ", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)1.0); ) + CASE('e', "1 step CloseBox ", motorBox.RunDegrees(CLOCKWISE, (float)1.0); ) + CASE('f', "Dancer Clock Wise ", motorDancer.RunInfinite(CLOCKWISE); ) + CASE('j', "Dancer Counter Clock Wise ", motorDancer.RunInfinite(COUNTERCLOCKWISE); ) + CASE('s', "STOP ", stop_all(); ) + CASE('m', "Music 1", PLAY_MUSIC(song_xfile,buzzer); ) + CASE('n', "Music 2", PLAY_MUSIC(song_lightmyfire,buzzer); ) + CASE('p', "Music 3", PLAY_MUSIC(song_greensleaves,buzzer); ) + CASE('q', "Music 4", PLAY_MUSIC(song_christmas,buzzer); ) + CASE('r', "Music 5", PLAY_MUSIC(song_happy_birthday,buzzer); ) + CASE('l', "Light ", + ledBand.StopRotation(); ledBand.ResetColor(); + ledBand.InsertColorNtimes(3,YELLOW,5.0); + ledBand.InsertColorNtimes(1,PURPLE,5); + ledBand.InsertColorNtimes(4,GREEN,10.0); + ledBand.StartRotation(0.1); + ) + + default : + DEBUG("invalid command; use: 'h' for help()"); } } }