Electronica
/
PROYECTO
poyecto
Diff: main_control_motor.cpp
- Revision:
- 0:cf20365296f5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main_control_motor.cpp Tue Dec 14 10:50:46 2021 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); // tx, rx + +DigitalOut dirAMotor(A4); +PwmOut dirBMotor(A3); +InterruptIn encoderA(A2); + +int contador=0; + +void encoderAIrq() +{ + contador++; +} + +int main() +{ + pc.baud(115200); + encoderA.rise(&encoderAIrq); // attach the address of the flip function to the rising edge + dirAMotor=0; + while (true) { + for (float i=0; i<1; i=i+0.01) { + dirBMotor=i; + wait(0.100); + } + pc.printf("Vueltas: %d\r\n",contador); + contador=0; + } +}