eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Committer:
garphil
Date:
Mon Jul 17 11:46:27 2017 +0000
Revision:
20:cdbc31a89c7f
Parent:
17:04c9b524dd94
Child:
24:59caeaa9f82d
Moved all individual libraries in CREALIB

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fbd38 16:8ae70f0b8fca 1 /*
garphil 20:cdbc31a89c7f 2 * LaLaBOX program
fbd38 16:8ae70f0b8fca 3 *
garphil 20:cdbc31a89c7f 4 * Version 3.0, July 17, 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 17:04c9b524dd94 11 Serial pc_uart(USBTX, USBRX);
fbd38 16:8ae70f0b8fca 12
garphil 20:cdbc31a89c7f 13 // ---------------- Local global variables --------------
garphil 20:cdbc31a89c7f 14
garphil 20:cdbc31a89c7f 15 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 20:cdbc31a89c7f 16 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 20:cdbc31a89c7f 17 Music song_xfile("Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b.");
garphil 20:cdbc31a89c7f 18 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 20:cdbc31a89c7f 19
garphil 2:050f12806bc5 20 // ---------------- PIN DEFINITIONS ---------------------
garphil 2:050f12806bc5 21 DigitalOut myled(LED1); // Blinking LED
garphil 20:cdbc31a89c7f 22 InterruptIn buttonBox(PB_1);
garphil 20:cdbc31a89c7f 23
garphil 20:cdbc31a89c7f 24 // --- Define the Four PINs & Time of movement used for Motor drive -----
garphil 20:cdbc31a89c7f 25 Motor motorBox(PA_8, PA_11, PB_5, PB_4, 5000);
garphil 20:cdbc31a89c7f 26 Motor motorDancer(PA_4, PA_13, PA_1, PA_0, 2000);
garphil 20:cdbc31a89c7f 27
garphil 20:cdbc31a89c7f 28 // PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW
garphil 20:cdbc31a89c7f 29 LED_WS2812 ledBand(PB_3,16);
garphil 20:cdbc31a89c7f 30
garphil 20:cdbc31a89c7f 31 // --- Define PB_0 as the output of PWM use for Tones -----
garphil 20:cdbc31a89c7f 32 Buzzer buzzer(PB_0);
garphil 20:cdbc31a89c7f 33
garphil 20:cdbc31a89c7f 34 Note la("A#4",50); //the sound
garphil 20:cdbc31a89c7f 35
garphil 20:cdbc31a89c7f 36 void help() // Display list of Commands
garphil 20:cdbc31a89c7f 37 {
garphil 20:cdbc31a89c7f 38 DEBUG("List of commands:\n\r");
garphil 20:cdbc31a89c7f 39 DEBUG(" h --> Help, display list of cammands\n\r");
garphil 20:cdbc31a89c7f 40 }
garphil 2:050f12806bc5 41
garphil 20:cdbc31a89c7f 42 /* Stop all processes */
garphil 20:cdbc31a89c7f 43 void stop_all()
garphil 20:cdbc31a89c7f 44 {
garphil 20:cdbc31a89c7f 45 motorBox.Stop();
garphil 20:cdbc31a89c7f 46 motorDancer.Stop();
garphil 20:cdbc31a89c7f 47 ledBand.ResetColor();
garphil 20:cdbc31a89c7f 48 buzzer.stopPlay();
garphil 20:cdbc31a89c7f 49 }
garphil 20:cdbc31a89c7f 50
garphil 20:cdbc31a89c7f 51 /* Interrupt routine, switch of end of course */
garphil 20:cdbc31a89c7f 52 void clicked()
garphil 20:cdbc31a89c7f 53 {
garphil 20:cdbc31a89c7f 54 DEBUG("End of Course\n\r");
garphil 20:cdbc31a89c7f 55 stop_all();
garphil 20:cdbc31a89c7f 56 }
garphil 20:cdbc31a89c7f 57
garphil 20:cdbc31a89c7f 58 /* Launch Light Mega Show ! */
garphil 20:cdbc31a89c7f 59 void illuminati() {
garphil 20:cdbc31a89c7f 60 ledBand.StopRotation(); ledBand.ResetColor();
garphil 20:cdbc31a89c7f 61 ledBand.InsertColorNtimes(3,YELLOW,5.0);
garphil 20:cdbc31a89c7f 62 ledBand.InsertColorNtimes(1,PURPLE,5);
garphil 20:cdbc31a89c7f 63 ledBand.InsertColorNtimes(4,GREEN,10.0);
garphil 20:cdbc31a89c7f 64 ledBand.StartRotation(0.1);
garphil 20:cdbc31a89c7f 65
garphil 20:cdbc31a89c7f 66 }
garphil 5:f62e799558c3 67
fbd38 16:8ae70f0b8fca 68 /* Main Routine */
fbd38 16:8ae70f0b8fca 69 int main()
fbd38 16:8ae70f0b8fca 70 {
garphil 1:ab4c9a0a5374 71 myled = 1; // To see something is alive
garphil 20:cdbc31a89c7f 72 bool flaghelp;
garphil 20:cdbc31a89c7f 73 DEBUG("------------------------------------------\n\r");
garphil 20:cdbc31a89c7f 74 DEBUG("----- LaLaBox (CreaLab) version 2.0 ----\n\r");
garphil 20:cdbc31a89c7f 75 DEBUG("------------------------------------------\n\r");
garphil 20:cdbc31a89c7f 76 ledBand.SetColor(WHITE);
garphil 20:cdbc31a89c7f 77 DEBUG("SystemCoreClock = %d Hz =\n\r", SystemCoreClock);
garphil 20:cdbc31a89c7f 78 DEBUG("Wait 2s\n\r");
garphil 20:cdbc31a89c7f 79
garphil 20:cdbc31a89c7f 80 /* Connect EoC button */
garphil 20:cdbc31a89c7f 81 CATCH_BUTTON(buttonBox,clicked);
garphil 20:cdbc31a89c7f 82
garphil 20:cdbc31a89c7f 83 /* Play a tone */
garphil 20:cdbc31a89c7f 84 PLAY_NOTE(la, buzzer);
garphil 20:cdbc31a89c7f 85
garphil 20:cdbc31a89c7f 86 wait(2); // Some delay
garphil 20:cdbc31a89c7f 87 myled = 0; // Real stuff starts here
garphil 20:cdbc31a89c7f 88 ledBand.SetColor(BLACK);
garphil 20:cdbc31a89c7f 89 DEBUG("Enter a command : \n\r");
garphil 20:cdbc31a89c7f 90
garphil 20:cdbc31a89c7f 91 while(1) {
garphil 20:cdbc31a89c7f 92 char command; // Command to execute
garphil 20:cdbc31a89c7f 93 DEBUG(">> ");
garphil 20:cdbc31a89c7f 94 command = bt_uart.getc();
garphil 20:cdbc31a89c7f 95 DEBUG("%c", command);
garphil 20:cdbc31a89c7f 96 flaghelp = false;
garphil 20:cdbc31a89c7f 97 switch (command) {
garphil 20:cdbc31a89c7f 98 case 'h':
garphil 20:cdbc31a89c7f 99 help();
garphil 20:cdbc31a89c7f 100 flaghelp=true;
garphil 20:cdbc31a89c7f 101 CASE('o', "OpenBox", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)140.0); )
garphil 20:cdbc31a89c7f 102 CASE('c', "CloseBox", motorBox.RunDegrees(CLOCKWISE, (float)140.0); )
garphil 20:cdbc31a89c7f 103 CASE('d', "1 step OpenBox ", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)1.0); )
garphil 20:cdbc31a89c7f 104 CASE('e', "1 step CloseBox ", motorBox.RunDegrees(CLOCKWISE, (float)1.0); )
garphil 20:cdbc31a89c7f 105 CASE('f', "Dancer Clock Wise ", motorDancer.RunInfinite(CLOCKWISE); )
garphil 20:cdbc31a89c7f 106 CASE('j', "Dancer Counter Clock Wise ", motorDancer.RunInfinite(COUNTERCLOCKWISE); )
garphil 20:cdbc31a89c7f 107 CASE('s', "STOP ", stop_all(); )
garphil 20:cdbc31a89c7f 108 CASE('m', "Music 1", PLAY_MUSIC(song_xfile,buzzer); )
garphil 20:cdbc31a89c7f 109 CASE('n', "Music 2", PLAY_MUSIC(song_lightmyfire,buzzer); )
garphil 20:cdbc31a89c7f 110 CASE('p', "Music 3", PLAY_MUSIC(song_greensleaves,buzzer); )
garphil 20:cdbc31a89c7f 111 CASE('q', "Music 4", PLAY_MUSIC(song_christmas,buzzer); )
garphil 20:cdbc31a89c7f 112 CASE('l', "Light ", illuminati(); )
garphil 20:cdbc31a89c7f 113
garphil 20:cdbc31a89c7f 114 default :
garphil 20:cdbc31a89c7f 115 DEBUG("invalid command; use: 'h' for help()");
garphil 20:cdbc31a89c7f 116 }
garphil 20:cdbc31a89c7f 117 }
garphil 20:cdbc31a89c7f 118 }