Software that allows basic remote control of the position of a servo (schematic included in the comments)
Fork of Nucleo_sg90_remote_control by
main.cpp@0:7a91558f8c41, 2017-01-30 (annotated)
- Committer:
- YPROY
- Date:
- Mon Jan 30 05:20:16 2017 +0000
- Revision:
- 0:7a91558f8c41
- Child:
- 1:df2cee74ab8b
premier essai avec calibration de tower pro sg90
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YPROY | 0:7a91558f8c41 | 1 | #include "mbed.h" |
YPROY | 0:7a91558f8c41 | 2 | |
YPROY | 0:7a91558f8c41 | 3 | PwmOut mypwm(PA_7); |
YPROY | 0:7a91558f8c41 | 4 | InterruptIn monBouton(USER_BUTTON); |
YPROY | 0:7a91558f8c41 | 5 | int compteur; |
YPROY | 0:7a91558f8c41 | 6 | int cycle[]={700, 1550, 2500, 1550}; |
YPROY | 0:7a91558f8c41 | 7 | void pressed(void) |
YPROY | 0:7a91558f8c41 | 8 | { |
YPROY | 0:7a91558f8c41 | 9 | compteur++; |
YPROY | 0:7a91558f8c41 | 10 | if (compteur >= sizeof(cycle)/sizeof(int)) |
YPROY | 0:7a91558f8c41 | 11 | { |
YPROY | 0:7a91558f8c41 | 12 | compteur = 0; |
YPROY | 0:7a91558f8c41 | 13 | } |
YPROY | 0:7a91558f8c41 | 14 | mypwm.pulsewidth_us(cycle[compteur]); |
YPROY | 0:7a91558f8c41 | 15 | } |
YPROY | 0:7a91558f8c41 | 16 | |
YPROY | 0:7a91558f8c41 | 17 | DigitalOut myled(LED1); |
YPROY | 0:7a91558f8c41 | 18 | |
YPROY | 0:7a91558f8c41 | 19 | int main() { |
YPROY | 0:7a91558f8c41 | 20 | compteur = 0; |
YPROY | 0:7a91558f8c41 | 21 | mypwm.period_ms(20); |
YPROY | 0:7a91558f8c41 | 22 | mypwm.pulsewidth_us(500); |
YPROY | 0:7a91558f8c41 | 23 | |
YPROY | 0:7a91558f8c41 | 24 | // printf("pwm set to %.2f %%\n", mypwm.read() * 100); |
YPROY | 0:7a91558f8c41 | 25 | monBouton.fall(&pressed); |
YPROY | 0:7a91558f8c41 | 26 | |
YPROY | 0:7a91558f8c41 | 27 | while(1) { |
YPROY | 0:7a91558f8c41 | 28 | myled = !myled; |
YPROY | 0:7a91558f8c41 | 29 | wait(1); |
YPROY | 0:7a91558f8c41 | 30 | } |
YPROY | 0:7a91558f8c41 | 31 | } |