controllo velocita motore con tasto user

Dependencies:   ArduinoMotorShield mbed

Revision:
0:a3a22a35e75c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 18 11:32:22 2016 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "ArduinoMotorShield.hpp"
+
+Serial pc(SERIAL_TX, SERIAL_RX);
+ArduinoMotorShield motore;
+DigitalIn mybutton(USER_BUTTON);
+DigitalOut myled(LED1);
+Timer timer;
+float velocita=0.0;
+float speed=0.1;
+
+int main() {
+  while(1) {
+    
+    //motore.SetMotorPolarity( ArduinoMotorShield::MOTOR_A, ArduinoMotorShield::MOTOR_FORWARD );
+   // motore.SetMotorPolarity( ArduinoMotorShield::MOTOR_B, ArduinoMotorShield::MOTOR_BACKWARD );
+    motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, speed);
+    if(mybutton==0)        timer.start();
+    if(mybutton!=0){
+        timer.stop();
+        if(timer.read()> 0.5 && velocita< 1) {
+            velocita+=0.1;
+            timer.reset();
+            motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ;
+                               }
+        else 
+            if(velocita>-1){
+            velocita-=0.1;
+            motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ;
+                            }
+                    }
+        
+   /* if (mybutton==0) { // Button is pressed
+      myled = !myled; // Toggle the LED state
+      wait(0.5); // 200 ms
+    }*/
+  }
+}
+ 
\ No newline at end of file