eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Revision:
10:983ed805d74f
Parent:
9:6b8118063819
Child:
11:c0728c05f977
diff -r 6b8118063819 -r 983ed805d74f main.cpp
--- a/main.cpp	Wed Oct 05 18:55:27 2016 +0000
+++ b/main.cpp	Thu Oct 06 11:27:20 2016 +0000
@@ -15,14 +15,14 @@
 InterruptIn  myButton(USER_BUTTON);
 
 // --- 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_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,8);
 
 // --- Define PC_8 as the output of PWM use for Tones -----
-Buzzer buzzer(PC_8);
+// Buzzer buzzer(PC_8);
 
 Note la("A#4",50);  //the sound
 
@@ -33,37 +33,25 @@
 {
     DEBUG("List of commands:\n\r");
     DEBUG(" h --> Help, display list of cammands\n\r");
-    DEBUG(" z --> Go to motor zero\n\r");
-    DEBUG(" k --> Calibrate motor\n\r");
-    DEBUG(" n dddd --> define Number of coils (default=100)\n\r");
-    DEBUG(" c --> define Clockwise (default)\n\r");
-    DEBUG(" a --> define Anti-clockwise\n\r");
-    DEBUG(" m --> Memorise configuration\n\r");
-    DEBUG(" l --> List current configuration\n\r");
-    DEBUG(" w --> start Wiring the coils\n\r");
-    DEBUG(" p --> Pause wiring\n\r");
-    DEBUG(" r --> Resume wiring\n\r");
-    DEBUG(" s --> Stop (abort) wiring\n\r");
-    DEBUG(" [space] --> print remaining Motor steps\n\r");
-}
+ }
 
 void pressed() {
     state++;
     switch(state) {
         case 1:
-            motorDancer.Stop();
-            motorBox.RunDegrees(CLOCKWISE, (float)90.0);   
+ //           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);    
+//            motorDancer.RunDegrees(CLOCKWISE, (float)180.0);    
+ //           motorBox.RunDegrees(COUNTERCLOCKWISE, (float)180.0);    
             ledBand.SetColor(0x0000FF);
-            ledBand.SetIntensity(50.0);
+           ledBand.SetIntensity(20.0);
         break;
         case 3:
               ledBand.InsertColor(BLUE);
-              ledBand.InsertColor(WHITE);
+             ledBand.InsertColor(WHITE);
               ledBand.InsertColor(RED);
         break;
         case 4:          
@@ -71,17 +59,17 @@
         break;
         case 5:
              ledBand.StopRotation();
-        //   ledBand.ResetColor();
-            ledBand.InsertColorNtimes(3,BLUE);
+           ledBand.ResetColor();
+           ledBand.InsertColorNtimes(3,BLUE,20.0);
             ledBand.InsertColorNtimes(1,WHITE);
-           ledBand.InsertColorNtimes(4,RED,50.0);
+          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();
-            motorDancer.Stop();
-            motorBox.Stop();
+ //           motorDancer.Stop();
+ //           motorBox.Stop();
             state = 0;
          break;
     }
@@ -89,25 +77,43 @@
   
 }
 
+
+
 int main() {
     myled = 1;      // To see something is alive
-    DEBUG("\n\n\r");
+    DEBUG("\n\n%d\r",SystemCoreClock);
     DEBUG("------------------------------------------\n\r"); 
     DEBUG("----- LaLaBox (CreaLab)     version 1.0 ----\n\r");
     DEBUG("------------------------------------------\n\r"); 
     help();
     DEBUG("------------------------------------------\n\r"); 
-    ledBand.SetColor(BLACK);
- 
+     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);
     
-    PLAY_NOTE(la, buzzer);             
+ //   PLAY_NOTE(la, buzzer);             
 
     wait(2);        // Some delay
     myled = 0;      // Real stuff starts here
-     ledBand.SetColor(BLACK);
-
-     motorBox.SetDirection(CLOCKWISE); 
+ 
+ //    motorBox.SetDirection(CLOCKWISE); 
    while(1) {
         char command;   // Command to execute
         DEBUG(">> ");
@@ -116,20 +122,16 @@
 
         switch (command) {
         case 'h': help(); break;
-        case 'z': motorBox.SetZero(); break;
-        case 'k': motorBox.TestMotor(); break;
+//        case 'z': motorBox.SetZero(); break;
+ //       case 'k': motorBox.TestMotor(); break;
         case 'c': 
             DEBUG(" -- Direction CLOCKWISE --\n\r");
-            motorBox.SetDirection(CLOCKWISE); 
+  //          motorBox.SetDirection(CLOCKWISE); 
             break;
         case 'a': 
             DEBUG(" -- Direction COUNTER CLOCKWISE --\n\r");
-            motorBox.SetDirection(COUNTERCLOCKWISE);  
+  //          motorBox.SetDirection(COUNTERCLOCKWISE);  
             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()");
         }
     }