eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Revision:
6:2f4867594333
Parent:
5:f62e799558c3
Child:
7:592af6237038
diff -r f62e799558c3 -r 2f4867594333 main.cpp
--- a/main.cpp	Fri Jun 24 15:00:15 2016 +0000
+++ b/main.cpp	Tue Aug 23 11:34:10 2016 +0000
@@ -3,28 +3,30 @@
 // ---------------- Local global variables --------------
     
 // --- Sound ---
-char *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";
-char *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";
-char *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";
-char *song_xfile = "Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b.";
-char *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,";
+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");
+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");
+Music song_xfile("Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b.");
+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,");
 
 // ---------------- PIN DEFINITIONS ---------------------
 DigitalOut myled(LED1);     // Blinking LED
 InterruptIn  myButton(USER_BUTTON);
 
-// --- Define the Foor PINs used for Motor drive -----
-Motor motorBox(PA_9, PC_7, PB_6, PA_7);
-// Motor motorDancer(PA_9, PC_7, PB_6, PA_7)
+// --- Define the Four PINs & Time of movement used for Motor drive -----
+Motor motorBox(PA_9, PC_7, PB_6, PA_7, 30000);
+Motor motorDancer(PA_8, PB_10, PB_4, PB_5, 10000);
+
+// PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW
+LED_WS2812 ledBand(D3,16);
 
 // --- Define PC_8 as the output of PWM use for Tones -----
 Buzzer buzzer(PC_8);
 
-Music* pMusic=0;    //the song
 Note la("A#4",50);  //the sound
 
 // init
-bool state = false;
+int state = 0;
 
 void help() // Display list of Commands
 {
@@ -45,12 +47,43 @@
 }
 
 void pressed() {
-    if(state) {
-        motorBox.RunDegrees(DIRECTION_CLOCKWISE, (float)90.0);    
-    } else {
-        motorBox.RunDegrees(DIRECTION_COUNTERCLOCKWISE, (float)360.0);    
+    state++;
+    switch(state) {
+        case 1:
+            motorDancer.Stop();
+            motorBox.RunDegrees(CLOCKWISE, (float)90.0);   
+            ledBand.SetColor(WHITE);
+        break;
+        case 2:
+            motorDancer.RunDegrees(CLOCKWISE, (float)180.0);    
+            motorBox.RunDegrees(COUNTERCLOCKWISE, (float)180.0);    
+            ledBand.SetColor(0xFF00FF);
+            ledBand.SetIntensity(50.0);
+        break;
+        case 3:
+            ledBand.InsertColor(BLUE);
+            ledBand.InsertColor(WHITE);
+            ledBand.InsertColor(RED);
+        break;
+        case 4:
+            ledBand.StartRotation(0.1);
+        break;
+        case 5:
+            ledBand.ResetColor();
+            ledBand.InsertColorNtimes(5,BLUE);
+            ledBand.InsertColorNtimes(2,WHITE);
+            ledBand.InsertColorNtimes(5,RED,50.0);
+            ledBand.StartRotation(0.01);
+            PLAY_MUSIC(song_happy_birthday, buzzer);
+        break;
+       default:
+            ledBand.StopRotation(0.1);
+            motorDancer.Stop();
+            motorBox.Stop();
+            state = 0;
+            myled = !myled;      // To see something is alive
+        break;
     }
-    state = ! state;
 }
 
 int main() {
@@ -63,12 +96,14 @@
     DEBUG("------------------------------------------\n\r"); 
  
     myButton.fall(&pressed);
- 
-    wait(5);        // Some delay
+    
+    PLAY_NOTE(la, buzzer);
+    
+    wait(2);        // Some delay
     myled = 0;      // Real stuff starts here
  
  
-   motorBox.SetDirection(DIRECTION_CLOCKWISE); 
+   motorBox.SetDirection(CLOCKWISE); 
    while(1) {
         char command;   // Command to execute
         DEBUG(">> ");
@@ -77,20 +112,20 @@
 
         switch (command) {
         case 'h': help(); break;
-        case 'z': motorBox.SetCommand(MOTOR_zero); break;
+        case 'z': motorBox.SetZero(); break;
         case 'k': motorBox.TestMotor(); break;
         case 'c': 
             DEBUG(" -- Direction CLOCKWISE --\n\r");
-            motorBox.SetDirection(DIRECTION_CLOCKWISE); 
+            motorBox.SetDirection(CLOCKWISE); 
             break;
         case 'a': 
             DEBUG(" -- Direction COUNTER CLOCKWISE --\n\r");
-            motorBox.SetDirection(DIRECTION_COUNTERCLOCKWISE);  
+            motorBox.SetDirection(COUNTERCLOCKWISE);  
             break;
-        case 'w': DEBUG(" -- Starting --\n\r"); motorBox.SetCommand(MOTOR_start);    break;
-        case 'p': DEBUG(" -- Pause    --\n\r"); motorBox.SetCommand(MOTOR_pause);   break;
-        case 'r': DEBUG(" -- Re-Start --\n\r"); motorBox.SetCommand(MOTOR_restart); break;
-        case 's': DEBUG(" -- Stop     --\n\r"); motorBox.SetCommand(MOTOR_stop);    break;
+        case 'w': DEBUG(" -- Starting --\n\r"); motorBox.Start();    break;
+        case 'p': DEBUG(" -- Pause    --\n\r"); motorBox.Stop();   break;
+        case 'r': DEBUG(" -- Re-Start --\n\r"); motorBox.Restart(); break;
+        case 's': DEBUG(" -- Stop     --\n\r"); motorBox.Stop();    break;
         default : DEBUG("invalid command; use: 'h' for help()");
         }
     }