programma che gestisce velocità del motore con comunicazione seriale pc microcontrollore

Dependencies:   ArduinoMotorShield mbed

Files at this revision

API Documentation at this revision

Comitter:
mikteam10
Date:
Tue Oct 18 11:23:29 2016 +0000
Commit message:
MotoreSeriale

Changed in this revision

ArduinoMotorShield.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 7a07d17ecd48 ArduinoMotorShield.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ArduinoMotorShield.lib	Tue Oct 18 11:23:29 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/johnb/code/ArduinoMotorShield/#b6bd7c434ab5
diff -r 000000000000 -r 7a07d17ecd48 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 18 11:23:29 2016 +0000
@@ -0,0 +1,45 @@
+#include "mbed.h"
+#include "ArduinoMotorShield.hpp"
+
+
+ArduinoMotorShield motore;
+DigitalIn mybutton(USER_BUTTON);
+DigitalOut myled(LED1);
+Timer timer;
+
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut led(LED1);
+
+float speed1 =0.1;    // velocita di start del motore in forward
+float speed =-0.1;    //velocita del motore in backward
+bool partito= false;
+float velocita = 0.0; // variabile velocita da incrementare o decrementare da tastiera
+float brightness = 0.0;  //variabile per aumentare o decrementare la luce del led1
+ 
+int main() {
+    pc.printf("Press 'u' per accelerare del 10%, 'd' per decelerare del 10% \n");
+ 
+    while(1) {
+       if(mybutton==0){
+            motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, speed1); //alla pressione del tasto user il motore parte in avanti
+        partito=true;
+        }
+                if(partito){
+        char c = pc.getc();
+        
+        if((c == 'u') && (velocita < 1.0)) {
+            brightness += 0.1;
+            velocita+=0.1;
+            led = brightness;
+            motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ;
+                                           }
+        if((c == 'd') && (velocita>-1.0)){
+            velocita-=0.1;
+            brightness -= 0.1;
+            led = brightness;
+            motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ;
+                                            }
+ 
+                          }
+             }
+}
\ No newline at end of file
diff -r 000000000000 -r 7a07d17ecd48 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 18 11:23:29 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file