eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Revision:
11:c0728c05f977
Parent:
10:983ed805d74f
Child:
12:60c531df03fd
--- a/main.cpp	Thu Oct 06 11:27:20 2016 +0000
+++ b/main.cpp	Tue Oct 11 22:22:27 2016 +0000
@@ -13,16 +13,19 @@
 // ---------------- PIN DEFINITIONS ---------------------
 DigitalOut myled(LED1);     // Blinking LED
 InterruptIn  myButton(USER_BUTTON);
+InterruptIn  buttonBox(PB_9);
 
 // --- 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);
+ Motor motorBox(PA_6, PA_7, PB_6, PC_7, 20000);
+ Motor motorDancer(PA_4,PB_0,PC_1,PC_0, 10000);
+ 
+ 
 
 // PIN & number of LEDS. Available color ==> BLUE, LIGHTBLUE, RED, GREEN, BLACK, WHITE, PURPLE, PINK, YELLOW
-LED_WS2812 ledBand(D3,8);
+LED_WS2812 ledBand(D3,16);
 
 // --- Define PC_8 as the output of PWM use for Tones -----
-// Buzzer buzzer(PC_8);
+ Buzzer buzzer(PB_8);
 
 Note la("A#4",50);  //the sound
 
@@ -35,17 +38,24 @@
     DEBUG(" h --> Help, display list of cammands\n\r");
  }
 
+void clicked() {
+    motorBox.Stop();
+    motorDancer.Stop();
+    ledBand.ResetColor();
+}
+
 void pressed() {
     state++;
     switch(state) {
         case 1:
- //           motorDancer.Stop();
- //           motorBox.RunDegrees(CLOCKWISE, (float)90.0);   
+            motorDancer.Stop();
+            motorBox.RunDegrees(COUNTERCLOCKWISE, (float)60.0);   
+           motorDancer.RunDegrees(COUNTERCLOCKWISE, 6*(float)360.0);   
             ledBand.SetColor(WHITE);
         break;
         case 2:
 //            motorDancer.RunDegrees(CLOCKWISE, (float)180.0);    
- //           motorBox.RunDegrees(COUNTERCLOCKWISE, (float)180.0);    
+            motorBox.RunDegrees(CLOCKWISE, (float)100.0);    
             ledBand.SetColor(0x0000FF);
            ledBand.SetIntensity(20.0);
         break;
@@ -64,7 +74,7 @@
             ledBand.InsertColorNtimes(1,WHITE);
           ledBand.InsertColorNtimes(4,RED,50.0);
             ledBand.StartRotation(0.1);  
- //           PLAY_MUSIC(song_happy_birthday, buzzer);
+      //      PLAY_MUSIC(song_happy_birthday, buzzer);
         break;
        default:
             ledBand.StopRotation();
@@ -79,8 +89,10 @@
 
 
 
+
 int main() {
     myled = 1;      // To see something is alive
+    bool flaghelp;
     DEBUG("\n\n%d\r",SystemCoreClock);
     DEBUG("------------------------------------------\n\r"); 
     DEBUG("----- LaLaBox (CreaLab)     version 1.0 ----\n\r");
@@ -90,48 +102,42 @@
      ledBand.SetColor(BLACK);
     DEBUG("SystemCoreClock = %d Hz = %f\n\r", SystemCoreClock); 
 
-Timer opt;
-int last = 0;
-
-int sum=0;
-for(int kk=0; kk<20;kk++) {
-    opt.reset();    
-    opt.start();
-                  myled = 1;
-            for (int j=0; j < 10000; j++) {
-                __nop();
-            }
-            opt.stop();
-    sum=sum+opt.read_us();
-    printf("read %d\n\r",opt.read_us());
-}
-printf("sum=%d ==> average = %f\n\r",sum, sum/20.0);
-    CATCH_BUTTON(myButton,pressed);
+   CATCH_BUTTON(myButton,clicked);
+   CATCH_BUTTON(buttonBox,clicked);
+   buttonBox.mode(PullUp);
+   buttonBox.rise(&clicked);
     
  //   PLAY_NOTE(la, buzzer);             
 
     wait(2);        // Some delay
     myled = 0;      // Real stuff starts here
- 
- //    motorBox.SetDirection(CLOCKWISE); 
+
    while(1) {
         char command;   // Command to execute
         DEBUG(">> ");
         command = pc_uart.getc();
         DEBUG("%c", command);
-
+        flaghelp = false;
         switch (command) {
-        case 'h': help(); break;
-//        case 'z': motorBox.SetZero(); break;
- //       case 'k': motorBox.TestMotor(); break;
-        case 'c': 
-            DEBUG(" -- Direction CLOCKWISE --\n\r");
-  //          motorBox.SetDirection(CLOCKWISE); 
-            break;
-        case 'a': 
-            DEBUG(" -- Direction COUNTER CLOCKWISE --\n\r");
-  //          motorBox.SetDirection(COUNTERCLOCKWISE);  
-            break;
+        case 'h':    
+            DEBUG("List of commands:\n\r");
+            DEBUG(" h --> Help, display list of cammands\n\r");
+            flaghelp=true;
+        CASE('o', "OpenBox", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)60.0);    )   
+        CASE('c', "CloseBox", motorBox.RunDegrees(CLOCKWISE, (float)60.0);    )   
+        CASE('d', "1 step OpenBox ", motorBox.RunDegrees(COUNTERCLOCKWISE, (float)1.0);       )   
+        CASE('e', "1 step CloseBox ", motorBox.RunDegrees(CLOCKWISE, (float)1.0);       )   
+        CASE('f', "Dancer Clock Wise ", motorDancer.RunInfinite(CLOCKWISE);    )   
+        CASE('j', "Dancer Counter Clock Wise ", motorDancer.RunInfinite(COUNTERCLOCKWISE);    )   
+        CASE('s', "STOP ", clicked();   )   
+        CASE('l', "Light ", 
+           ledBand.StopRotation(); ledBand.ResetColor();
+           ledBand.InsertColorNtimes(3,BLUE,20.0);
+           ledBand.InsertColorNtimes(1,WHITE);
+           ledBand.InsertColorNtimes(4,RED,50.0);
+           ledBand.StartRotation(0.1);     
+        )   
+ 
         default : DEBUG("invalid command; use: 'h' for help()");
         }
     }