eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Revision:
5:f62e799558c3
Parent:
4:d452a7e3461a
Child:
6:2f4867594333
--- a/main.cpp	Fri Jun 17 14:58:17 2016 +0000
+++ b/main.cpp	Fri Jun 24 15:00:15 2016 +0000
@@ -11,6 +11,7 @@
 
 // ---------------- 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);
@@ -22,7 +23,8 @@
 Music* pMusic=0;    //the song
 Note la("A#4",50);  //the sound
 
-// --- Motor Routine
+// init
+bool state = false;
 
 void help() // Display list of Commands
 {
@@ -42,8 +44,16 @@
     DEBUG(" [space] --> print remaining Motor steps\n\r");
 }
 
+void pressed() {
+    if(state) {
+        motorBox.RunDegrees(DIRECTION_CLOCKWISE, (float)90.0);    
+    } else {
+        motorBox.RunDegrees(DIRECTION_COUNTERCLOCKWISE, (float)360.0);    
+    }
+    state = ! state;
+}
+
 int main() {
-    uint32_t NumberOfTurns;
     myled = 1;      // To see something is alive
     DEBUG("\n\n\r");
     DEBUG("------------------------------------------\n\r"); 
@@ -51,22 +61,24 @@
     DEBUG("------------------------------------------\n\r"); 
     help();
     DEBUG("------------------------------------------\n\r"); 
+ 
+    myButton.fall(&pressed);
+ 
     wait(5);        // Some delay
     myled = 0;      // Real stuff starts here
-     //
-    while(1) {
+ 
+ 
+   motorBox.SetDirection(DIRECTION_CLOCKWISE); 
+   while(1) {
         char command;   // Command to execute
-         DEBUG(">> ");
+        DEBUG(">> ");
         command = pc_uart.getc();
         DEBUG("%c", command);
+
         switch (command) {
         case 'h': help(); break;
         case 'z': motorBox.SetCommand(MOTOR_zero); break;
         case 'k': motorBox.TestMotor(); break;
-        case 'n':
-            pc_uart.scanf("%d", &NumberOfTurns);
-            motorBox.TurnMotor(NumberOfTurns);
-           break;
         case 'c': 
             DEBUG(" -- Direction CLOCKWISE --\n\r");
             motorBox.SetDirection(DIRECTION_CLOCKWISE);