eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Committer:
garphil
Date:
Mon Jul 17 11:32:14 2017 +0000
Revision:
19:aa99c24e4ee0
Parent:
18:92f4f2b44d6d
Moved everything in CREALIB;

Who changed what in which revision?

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