controllo velocita motore con tasto user
Dependencies: ArduinoMotorShield mbed
Revision 0:a3a22a35e75c, committed 2016-10-18
- Comitter:
- mikteam10
- Date:
- Tue Oct 18 11:32:22 2016 +0000
- Commit message:
- controllo velocita motore con timer e tasto user
Changed in this revision
diff -r 000000000000 -r a3a22a35e75c ArduinoMotorShield.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ArduinoMotorShield.lib Tue Oct 18 11:32:22 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/johnb/code/ArduinoMotorShield/#b6bd7c434ab5
diff -r 000000000000 -r a3a22a35e75c main.cpp --- /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
diff -r 000000000000 -r a3a22a35e75c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Oct 18 11:32:22 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3 \ No newline at end of file