Convert the pwm signal generated by reciever into a signal used by H-bridge

Dependencies:   PwmIn mbed

main.cpp

Committer:
fy17y2w
Date:
2019-05-06
Revision:
0:c66e5ca3bad6

File content as of revision 0:c66e5ca3bad6:

#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);
                 }
        }
                 
             
         
    
}