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@3:c5a79dbed82b, 2015-11-17 (annotated)
- Committer:
- spin7ion
- Date:
- Tue Nov 17 10:44:09 2015 +0000
- Revision:
- 3:c5a79dbed82b
- Parent:
- 2:f3268845c3b1
- Child:
- 4:0b614835f104
added 2nd servo;
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 | 2:f3268845c3b1 | 9 | int servopulsewidth=15000; |
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 | 2:f3268845c3b1 | 20 | if(signer>0 && servopulsewidth>19900){ |
spin7ion | 0:e1d95cf9daa8 | 21 | signer=-1; |
spin7ion | 0:e1d95cf9daa8 | 22 | }else if(signer<0 && servopulsewidth<10){ |
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 | 0:e1d95cf9daa8 | 27 | wait(0.25); |
spin7ion | 0:e1d95cf9daa8 | 28 | } |
spin7ion | 0:e1d95cf9daa8 | 29 | } |