Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
main.cpp@5:d4e53f381e99, 2015-11-20 (annotated)
- Committer:
- spin7ion
- Date:
- Fri Nov 20 17:18:50 2015 +0000
- Revision:
- 5:d4e53f381e99
- Parent:
- 4:0b614835f104
some bug fixes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spin7ion | 0:e1d95cf9daa8 | 1 | #include "mbed.h" |
spin7ion | 0:e1d95cf9daa8 | 2 | |
spin7ion | 1:e21d7c0748cf | 3 | PwmOut servo(PB_3); |
spin7ion | 3:c5a79dbed82b | 4 | PwmOut servo2(PB_4); |
spin7ion | 0:e1d95cf9daa8 | 5 | |
spin7ion | 0:e1d95cf9daa8 | 6 | DigitalOut myled(LED1); |
spin7ion | 0:e1d95cf9daa8 | 7 | |
spin7ion | 0:e1d95cf9daa8 | 8 | int main() { |
spin7ion | 4:0b614835f104 | 9 | int servopulsewidth=1500; |
spin7ion | 0:e1d95cf9daa8 | 10 | int signer=1; |
spin7ion | 1:e21d7c0748cf | 11 | |
spin7ion | 0:e1d95cf9daa8 | 12 | servo.period_us(20000); // servo requires a 20ms period |
spin7ion | 3:c5a79dbed82b | 13 | servo2.period_us(20000); // servo requires a 20ms period |
spin7ion | 0:e1d95cf9daa8 | 14 | servo.pulsewidth_us(servopulsewidth); |
spin7ion | 3:c5a79dbed82b | 15 | servo2.pulsewidth_us(servopulsewidth); |
spin7ion | 0:e1d95cf9daa8 | 16 | wait(2); |
spin7ion | 0:e1d95cf9daa8 | 17 | while (1) { |
spin7ion | 0:e1d95cf9daa8 | 18 | servopulsewidth+=signer; |
spin7ion | 0:e1d95cf9daa8 | 19 | |
spin7ion | 4:0b614835f104 | 20 | if(signer>0 && servopulsewidth>1990){ |
spin7ion | 0:e1d95cf9daa8 | 21 | signer=-1; |
spin7ion | 5:d4e53f381e99 | 22 | }else if(signer<0 && servopulsewidth<1000){ |
spin7ion | 0:e1d95cf9daa8 | 23 | signer=1; |
spin7ion | 0:e1d95cf9daa8 | 24 | } |
spin7ion | 0:e1d95cf9daa8 | 25 | servo.pulsewidth_us(servopulsewidth); |
spin7ion | 3:c5a79dbed82b | 26 | servo2.pulsewidth_us(servopulsewidth); |
spin7ion | 4:0b614835f104 | 27 | wait(0.05); |
spin7ion | 0:e1d95cf9daa8 | 28 | } |
spin7ion | 0:e1d95cf9daa8 | 29 | } |