Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ArduinoMotorShield mbed
Fork of motore2 by
main.cpp
00001 #include "mbed.h" 00002 #include "ArduinoMotorShield.hpp" 00003 00004 Ticker timer; 00005 ArduinoMotorShield motore; 00006 DigitalIn mybutton(USER_BUTTON); 00007 //DigitalOut myled(LED1); 00008 //Timer timer; 00009 Serial pc(USBTX, USBRX); // tx, rx 00010 PwmOut led(LED1); 00011 00012 float speed2 =-1.0; // velocita di start del motore in forward 00013 float speed =-0.1; //velocita del motore in backward 00014 float velocita = -0.15; // variabile velocita da incrementare o decrementare da tastiera per il motore A 00015 float velocita2 = -0.95; //variabile velocita da incrementare o decrementare da tastiera per il motore A 00016 float brightness = 0.0; //variabile per aumentare o decrementare la luce del led1 00017 bool brake; 00018 00019 00020 void attime(){ 00021 pc.printf("C1= %f \r\n", (motore.GetMotorCurrent( ArduinoMotorShield::MOTOR_A))); 00022 pc.printf("C2= %f \r\n", (motore.GetMotorCurrent( ArduinoMotorShield::MOTOR_B))); 00023 } 00024 00025 00026 int main() { 00027 pc.printf("Premere un tasto per accendere i motori \n\r "); 00028 pc.printf("Premere 'd' per accelerare il motore A e decelerare il motore B \n\r"); 00029 pc.printf("Premere 'u' per accelerare il motore B e decelerare il motore A \n\r"); 00030 00031 brake= false; 00032 char s='\0'; 00033 char c='\0'; 00034 char p='\0'; 00035 //while(s != 's') 00036 s = pc.getc(); 00037 00038 motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, speed); 00039 motore.SetMotorPower( ArduinoMotorShield::MOTOR_B, speed2); 00040 timer.attach(&attime, 0.5); 00041 00042 while(1) { 00043 c = pc.getc(); 00044 00045 if((c == 'u') && (velocita < 1.0)) { 00046 brightness += 0.05; 00047 velocita += 0.05; 00048 velocita2 -= 0.05; 00049 led = brightness; 00050 motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ; 00051 motore.SetMotorPower( ArduinoMotorShield::MOTOR_B, velocita2) ; 00052 pc.printf("\rV= %f\n\r" , velocita); 00053 pc.printf("\rV2= %f\n\r" , velocita2); 00054 00055 00056 } 00057 if((c == 'd') && (velocita>-1.0)){ 00058 velocita -= 0.05; 00059 velocita2 += 0.05; 00060 brightness -= 0.05; 00061 led = brightness; 00062 motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ; 00063 motore.SetMotorPower( ArduinoMotorShield::MOTOR_B, velocita2) ; 00064 pc.printf("\rV= %f\n\r" , velocita); 00065 pc.printf("\rV2= %f\n\r" , velocita2); 00066 00067 } 00068 00069 00070 if((c == 's') && (brake==false)){ 00071 motore.SetBrake( ArduinoMotorShield::MOTOR_A, 1) ; 00072 motore.SetBrake( ArduinoMotorShield::MOTOR_B, 1) ; 00073 brake=true; 00074 p = pc.getc(); 00075 if(p == 's'){ 00076 motore.SetBrake( ArduinoMotorShield::MOTOR_A, 0) ; 00077 motore.SetBrake( ArduinoMotorShield::MOTOR_B, 0) ; 00078 motore.SetMotorPower( ArduinoMotorShield::MOTOR_A, velocita) ; 00079 motore.SetMotorPower( ArduinoMotorShield::MOTOR_B, velocita2) ; 00080 brake=false; 00081 } 00082 } 00083 00084 00085 00086 } 00087 00088 00089 }
Generated on Wed Jul 13 2022 23:43:17 by
1.7.2
