RTES / Mbed 2 deprecated mbed_pwmLib

Dependencies:   mbed

main.cpp

Committer:
jiteshg
Date:
2015-10-08
Revision:
1:8c73948a0864
Parent:
0:fd080fb55bae
Child:
2:bf817b299c19

File content as of revision 1:8c73948a0864:

/*
Using pwm to run a servo motor
Connect the red wire of the servo motor to 3.3V and not 5V
*/
#include "mbed.h"
PwmOut pwm1(p21);
Serial pc(USBTX, USBRX);

int main() {
    pwm1.period_ms(20);
    
    while(1){
        char c = pc.getc();
        if(c=='1'){
            pwm1.write(0);
            wait(0.5);
            pwm1.write(0.0375); // 3.75% duty cycle - Open the gate
        }
        else{
            pwm1.write(0);
            wait(0.5);
            pwm1.write(0.1125); // 11.25% duty cycle - Close the gate
        }
    }
    return 0;
}