eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Committer:
garphil
Date:
Wed Oct 03 11:42:21 2018 +0000
Revision:
24:59caeaa9f82d
Parent:
20:cdbc31a89c7f
Child:
25:3d3ebfd0a73f
Added Debug Mode;

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