This version does not work on my pc however it should work if i look at all the data send to hidscope and de led which does it correct. We should tray another pc because my pc does give still some errors on the libaries
Dependencies: HIDScope MODSERIAL mbed
Fork of Milestone_1_Motor_DualDirection_potmeter_v2 by
main.cpp
- Committer:
- CasperK
- Date:
- 2018-09-28
- Revision:
- 3:f00ddd66fe39
- Parent:
- 2:735ca8577f31
- Child:
- 4:fe0b7e7b1de9
File content as of revision 3:f00ddd66fe39:
#include "mbed.h" #include "MODSERIAL.h" #include "HIDScope.h" PwmOut pwmpin(D6); PwmOut led(D10); AnalogIn potmeter(A5); DigitalIn button(D2); DigitalOut directionpin(D7); MODSERIAL pc(USBTX, USBRX); HIDScope scope(2); Ticker ticker; enum states{forward, stop, backwards}; states CurrentState; volatile float x; volatile float y; volatile float scaled_potmeter; volatile float c; void sendData() { scope.set(0,potmeter); //set the potmeter data to the first scope scope.set(1,x); scope.send(); //send the datapoints of the 2 motors } void Proces_states(void){ switch (CurrentState){ case forward: directionpin = 1; pwmpin.write(scaled_potmeter); //pwm of motor is potmeter value led.write(scaled_potmeter); //led is potmeter value break; case stop: // do nothing break; case backwards: directionpin = 0; c = scaled_potmeter*-1; pwmpin.write(c); //pwm of motor is potmeter value led.write(c); //led is potmeter value break; } } int main() { x = 1; //placeholder value for potmeter of second motor pwmpin.period_us(60); //60 microseconds PWM period, 16.7 kHz led.period_us(60); //60 microseconds ticker.attach(&sendData, 0.005f); //send data to hidscope at 200Hz while (true) { scaled_potmeter = (potmeter*2)-1; //scale potmeter from 0-1 to (-1 to 1) if (scaled_potmeter > 0) { CurrentState = forward; pc.printf("state = forward\r\n"); Proces_states(); } if (scaled_potmeter == 0) { CurrentState = stop; pc.printf("state = stop\r\n"); Proces_states(); } if (scaled_potmeter < 0) { CurrentState = backwards; pc.printf("state = backwards\r\n"); Proces_states(); } wait(0.2f); } }