javier vicente / Mbed 2 deprecated MASTER_DC_MOTOR_PWM

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Serial pc(USBTX, USBRX); // tx, rx
00004 
00005 DigitalOut dirAMotor(A4);
00006 PwmOut     dirBMotor(A3);
00007 InterruptIn encoderA(A2);
00008 
00009 int contador=0;
00010 
00011 void encoderAIrq()
00012 {
00013     contador++;
00014 }
00015 
00016 int main()
00017 {
00018     pc.baud(115200);
00019     encoderA.rise(&encoderAIrq);  // attach the address of the flip function to the rising edge
00020     dirAMotor=0;
00021     while (true) {
00022         for (float i=0; i<1; i=i+0.01) {
00023             dirBMotor=i;
00024             wait(0.100);
00025         }
00026         pc.printf("Vueltas: %d\r\n",contador);
00027         contador=0;
00028     }
00029 }