Yifan Weng
/
Buggyproject
Convert the pwm signal generated by reciever into a signal used by H-bridge
Diff: main.cpp
- Revision:
- 0:c66e5ca3bad6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 06 21:24:22 2019 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "PwmIn.h" + + +Timer t; +PwmOut white_up(PC_8),white_down(PC_9),gray_up(PC_6),gray_down(PB_8); +PwmIn lin(A0),rin(A1); +int main() +{ + white_up.period_ms(2.5); + white_down.period_ms(2.5); + gray_up.period_ms(2.5); + gray_down.period_ms(2.5); + while(1){ + if(lin.dutycycle()<0.59 ){ + gray_down.write(-(lin.dutycycle()-0.59)*4.34); + wait_ms(10); + } + else if(lin.dutycycle()>0.61){ + white_down.write((lin.dutycycle()-0.61)*4.54 ); + wait_ms(10); + } + else{ + white_down.write(0); + gray_down.write(0); + wait_ms(10); + } + if(rin.dutycycle()< 0.59){ + gray_up.write(-(rin.dutycycle()-0.59)*4.34 ); + wait_ms(10); + } + else if(rin.dutycycle()>0.61){ + white_up.write((rin.dutycycle()-0.61)*4.34 ); + wait_ms(10); + } + else{ + white_up.write(0); + gray_up.write(0); + wait_ms(10); + } + } + + + + +}