eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Committer:
garphil
Date:
Fri Sep 09 10:43:52 2016 +0000
Revision:
8:fb28b9ec6d6e
Parent:
7:592af6237038
Child:
9:6b8118063819
Hidden & for interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garphil 1:ab4c9a0a5374 1 #include "LaLaBox.h"
garphil 1:ab4c9a0a5374 2
garphil 1:ab4c9a0a5374 3 // ---------------- Local global variables --------------
garphil 1:ab4c9a0a5374 4
garphil 1:ab4c9a0a5374 5 // --- Sound ---
garphil 6:2f4867594333 6 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 7 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 8 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 9 Music song_xfile("Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b.");
garphil 6:2f4867594333 10 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 11
garphil 2:050f12806bc5 12 // ---------------- PIN DEFINITIONS ---------------------
garphil 2:050f12806bc5 13 DigitalOut myled(LED1); // Blinking LED
garphil 5:f62e799558c3 14 InterruptIn myButton(USER_BUTTON);
garphil 2:050f12806bc5 15
garphil 6:2f4867594333 16 // --- Define the Four PINs & Time of movement used for Motor drive -----
garphil 6:2f4867594333 17 Motor motorBox(PA_9, PC_7, PB_6, PA_7, 30000);
garphil 6:2f4867594333 18 Motor motorDancer(PA_8, PB_10, PB_4, PB_5, 10000);
garphil 6:2f4867594333 19
garphil 6:2f4867594333 20 // PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW
garphil 7:592af6237038 21 LED_WS2812 ledBand(D3,8);
garphil 2:050f12806bc5 22
garphil 1:ab4c9a0a5374 23 // --- Define PC_8 as the output of PWM use for Tones -----
garphil 1:ab4c9a0a5374 24 Buzzer buzzer(PC_8);
garphil 0:30cb0f6dad87 25
garphil 1:ab4c9a0a5374 26 Note la("A#4",50); //the sound
garphil 1:ab4c9a0a5374 27
garphil 5:f62e799558c3 28 // init
garphil 6:2f4867594333 29 int state = 0;
garphil 2:050f12806bc5 30
garphil 1:ab4c9a0a5374 31 void help() // Display list of Commands
garphil 1:ab4c9a0a5374 32 {
garphil 1:ab4c9a0a5374 33 DEBUG("List of commands:\n\r");
garphil 1:ab4c9a0a5374 34 DEBUG(" h --> Help, display list of cammands\n\r");
garphil 1:ab4c9a0a5374 35 DEBUG(" z --> Go to motor zero\n\r");
garphil 1:ab4c9a0a5374 36 DEBUG(" k --> Calibrate motor\n\r");
garphil 1:ab4c9a0a5374 37 DEBUG(" n dddd --> define Number of coils (default=100)\n\r");
garphil 1:ab4c9a0a5374 38 DEBUG(" c --> define Clockwise (default)\n\r");
garphil 1:ab4c9a0a5374 39 DEBUG(" a --> define Anti-clockwise\n\r");
garphil 1:ab4c9a0a5374 40 DEBUG(" m --> Memorise configuration\n\r");
garphil 1:ab4c9a0a5374 41 DEBUG(" l --> List current configuration\n\r");
garphil 1:ab4c9a0a5374 42 DEBUG(" w --> start Wiring the coils\n\r");
garphil 1:ab4c9a0a5374 43 DEBUG(" p --> Pause wiring\n\r");
garphil 1:ab4c9a0a5374 44 DEBUG(" r --> Resume wiring\n\r");
garphil 1:ab4c9a0a5374 45 DEBUG(" s --> Stop (abort) wiring\n\r");
garphil 1:ab4c9a0a5374 46 DEBUG(" [space] --> print remaining Motor steps\n\r");
garphil 1:ab4c9a0a5374 47 }
garphil 1:ab4c9a0a5374 48
garphil 5:f62e799558c3 49 void pressed() {
garphil 6:2f4867594333 50 state++;
garphil 6:2f4867594333 51 switch(state) {
garphil 6:2f4867594333 52 case 1:
garphil 6:2f4867594333 53 motorDancer.Stop();
garphil 6:2f4867594333 54 motorBox.RunDegrees(CLOCKWISE, (float)90.0);
garphil 6:2f4867594333 55 ledBand.SetColor(WHITE);
garphil 6:2f4867594333 56 break;
garphil 6:2f4867594333 57 case 2:
garphil 6:2f4867594333 58 motorDancer.RunDegrees(CLOCKWISE, (float)180.0);
garphil 6:2f4867594333 59 motorBox.RunDegrees(COUNTERCLOCKWISE, (float)180.0);
garphil 7:592af6237038 60 ledBand.SetColor(0x0000FF);
garphil 6:2f4867594333 61 ledBand.SetIntensity(50.0);
garphil 6:2f4867594333 62 break;
garphil 6:2f4867594333 63 case 3:
garphil 7:592af6237038 64 ledBand.InsertColor(BLUE);
garphil 7:592af6237038 65 ledBand.InsertColor(WHITE);
garphil 7:592af6237038 66 ledBand.InsertColor(RED);
garphil 6:2f4867594333 67 break;
garphil 7:592af6237038 68 case 4:
garphil 7:592af6237038 69 ledBand.StartRotation(1);
garphil 6:2f4867594333 70 break;
garphil 6:2f4867594333 71 case 5:
garphil 7:592af6237038 72 ledBand.StopRotation();
garphil 8:fb28b9ec6d6e 73 // ledBand.ResetColor();
garphil 7:592af6237038 74 ledBand.InsertColorNtimes(3,BLUE);
garphil 7:592af6237038 75 ledBand.InsertColorNtimes(1,WHITE);
garphil 7:592af6237038 76 ledBand.InsertColorNtimes(4,RED,50.0);
garphil 7:592af6237038 77 ledBand.StartRotation(0.1);
garphil 6:2f4867594333 78 PLAY_MUSIC(song_happy_birthday, buzzer);
garphil 6:2f4867594333 79 break;
garphil 6:2f4867594333 80 default:
garphil 7:592af6237038 81 ledBand.StopRotation();
garphil 6:2f4867594333 82 motorDancer.Stop();
garphil 6:2f4867594333 83 motorBox.Stop();
garphil 6:2f4867594333 84 state = 0;
garphil 7:592af6237038 85 break;
garphil 5:f62e799558c3 86 }
garphil 7:592af6237038 87 myled = !myled; // To see something is alive
garphil 7:592af6237038 88
garphil 5:f62e799558c3 89 }
garphil 5:f62e799558c3 90
garphil 0:30cb0f6dad87 91 int main() {
garphil 1:ab4c9a0a5374 92 myled = 1; // To see something is alive
garphil 1:ab4c9a0a5374 93 DEBUG("\n\n\r");
garphil 1:ab4c9a0a5374 94 DEBUG("------------------------------------------\n\r");
garphil 8:fb28b9ec6d6e 95 DEBUG("----- LaLaBox (CreaLab) version 1.0 ----\n\r");
garphil 1:ab4c9a0a5374 96 DEBUG("------------------------------------------\n\r");
garphil 1:ab4c9a0a5374 97 help();
garphil 1:ab4c9a0a5374 98 DEBUG("------------------------------------------\n\r");
garphil 5:f62e799558c3 99
garphil 8:fb28b9ec6d6e 100 CATCH_BUTTON(myButton,pressed);
garphil 6:2f4867594333 101
garphil 6:2f4867594333 102 PLAY_NOTE(la, buzzer);
garphil 6:2f4867594333 103
garphil 6:2f4867594333 104 wait(2); // Some delay
garphil 1:ab4c9a0a5374 105 myled = 0; // Real stuff starts here
garphil 5:f62e799558c3 106
garphil 5:f62e799558c3 107
garphil 6:2f4867594333 108 motorBox.SetDirection(CLOCKWISE);
garphil 5:f62e799558c3 109 while(1) {
garphil 1:ab4c9a0a5374 110 char command; // Command to execute
garphil 5:f62e799558c3 111 DEBUG(">> ");
garphil 1:ab4c9a0a5374 112 command = pc_uart.getc();
garphil 1:ab4c9a0a5374 113 DEBUG("%c", command);
garphil 5:f62e799558c3 114
garphil 1:ab4c9a0a5374 115 switch (command) {
garphil 1:ab4c9a0a5374 116 case 'h': help(); break;
garphil 6:2f4867594333 117 case 'z': motorBox.SetZero(); break;
garphil 4:d452a7e3461a 118 case 'k': motorBox.TestMotor(); break;
garphil 4:d452a7e3461a 119 case 'c':
garphil 4:d452a7e3461a 120 DEBUG(" -- Direction CLOCKWISE --\n\r");
garphil 6:2f4867594333 121 motorBox.SetDirection(CLOCKWISE);
garphil 1:ab4c9a0a5374 122 break;
garphil 4:d452a7e3461a 123 case 'a':
garphil 4:d452a7e3461a 124 DEBUG(" -- Direction COUNTER CLOCKWISE --\n\r");
garphil 6:2f4867594333 125 motorBox.SetDirection(COUNTERCLOCKWISE);
garphil 4:d452a7e3461a 126 break;
garphil 6:2f4867594333 127 case 'w': DEBUG(" -- Starting --\n\r"); motorBox.Start(); break;
garphil 6:2f4867594333 128 case 'p': DEBUG(" -- Pause --\n\r"); motorBox.Stop(); break;
garphil 6:2f4867594333 129 case 'r': DEBUG(" -- Re-Start --\n\r"); motorBox.Restart(); break;
garphil 6:2f4867594333 130 case 's': DEBUG(" -- Stop --\n\r"); motorBox.Stop(); break;
garphil 1:ab4c9a0a5374 131 default : DEBUG("invalid command; use: 'h' for help()");
garphil 1:ab4c9a0a5374 132 }
garphil 0:30cb0f6dad87 133 }
garphil 1:ab4c9a0a5374 134 }