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@1:e21d7c0748cf, 2015-11-16 (annotated)
- Committer:
- spin7ion
- Date:
- Mon Nov 16 18:01:52 2015 +0000
- Revision:
- 1:e21d7c0748cf
- Parent:
- 0:e1d95cf9daa8
- Child:
- 2:f3268845c3b1
fixed bracket
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 | 0:e1d95cf9daa8 | 4 | |
spin7ion | 0:e1d95cf9daa8 | 5 | DigitalOut myled(LED1); |
spin7ion | 0:e1d95cf9daa8 | 6 | |
spin7ion | 0:e1d95cf9daa8 | 7 | int main() { |
spin7ion | 0:e1d95cf9daa8 | 8 | int servopulsewidth=1500; |
spin7ion | 0:e1d95cf9daa8 | 9 | int signer=1; |
spin7ion | 1:e21d7c0748cf | 10 | |
spin7ion | 0:e1d95cf9daa8 | 11 | servo.period_us(20000); // servo requires a 20ms period |
spin7ion | 0:e1d95cf9daa8 | 12 | servo.pulsewidth_us(servopulsewidth); |
spin7ion | 0:e1d95cf9daa8 | 13 | wait(2); |
spin7ion | 0:e1d95cf9daa8 | 14 | while (1) { |
spin7ion | 0:e1d95cf9daa8 | 15 | servopulsewidth+=signer; |
spin7ion | 0:e1d95cf9daa8 | 16 | |
spin7ion | 1:e21d7c0748cf | 17 | if(signer>0 && servopulsewidth>1990){ |
spin7ion | 0:e1d95cf9daa8 | 18 | signer=-1; |
spin7ion | 0:e1d95cf9daa8 | 19 | }else if(signer<0 && servopulsewidth<10){ |
spin7ion | 0:e1d95cf9daa8 | 20 | signer=1; |
spin7ion | 0:e1d95cf9daa8 | 21 | } |
spin7ion | 0:e1d95cf9daa8 | 22 | servo.pulsewidth_us(servopulsewidth); |
spin7ion | 0:e1d95cf9daa8 | 23 | wait(0.25); |
spin7ion | 0:e1d95cf9daa8 | 24 | } |
spin7ion | 0:e1d95cf9daa8 | 25 | } |