Yves Roy
/
CLIMOILOU_FORMATION_MII_S
Programme qui génère du pwm
Fork of Nucleo_sg90_remote_control by
Diff: main.cpp
- Revision:
- 0:52104be74a8a
- Child:
- 1:39c0d160f44c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Mar 24 17:34:09 2017 +0000 @@ -0,0 +1,40 @@ +#include "mbed.h" +#define NUMBER_OF_POSITIONS sizeof(pulseDurationInMicroSeconds)/sizeof(int) +#define PWM_PERIOD_FOR_SG90_IN_MS 20 +#define PWM_PERIOD_FOR_MODULATION_IN_US 25 +DigitalOut myled(LED1); +PwmOut towerProSG90(D11); +//PwmOut remoteControlOutput(D10); +//PwmOut modulatingOutput(D9); +InterruptIn userButton(USER_BUTTON); +int index; +int pulseDurationInMicroSeconds[]= + {1500,1625,1750,1875,2000, 1875,1750,1625,1500,1375,1250,1125,1000,1125,1250,1375}; +void responseToUserButtonPressed(void) +{ + index++; + if (index >= NUMBER_OF_POSITIONS) + { + index = 0; + } + towerProSG90.pulsewidth_us(pulseDurationInMicroSeconds[index]); +// remoteControlOutput.pulsewidth_us(PWM_PERIOD_FOR_SG90_IN_MS*1000 - pulseDurationInMicroSeconds[index]); +} + +int main() { + index = 0; + towerProSG90.period_ms(PWM_PERIOD_FOR_SG90_IN_MS); + towerProSG90.pulsewidth_us(pulseDurationInMicroSeconds[index]); + // remoteControlOutput.period_ms(PWM_PERIOD_FOR_SG90_IN_MS); + // remoteControlOutput.pulsewidth_us(PWM_PERIOD_FOR_SG90_IN_MS*1000 - pulseDurationInMicroSeconds[index]); + // modulatingOutput.period_us(PWM_PERIOD_FOR_MODULATION_IN_US); + // modulatingOutput.pulsewidth_us(PWM_PERIOD_FOR_MODULATION_IN_US/2); + userButton.fall(&responseToUserButtonPressed); + // userLED = 1; + while(1) { + myled = 1; // LED is ON + wait(0.2); // 200 ms + myled = 0; // LED is OFF + wait(1.0); // 1 sec + } +}