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@0:e1d95cf9daa8, 2015-11-16 (annotated)
- Committer:
- spin7ion
- Date:
- Mon Nov 16 17:43:35 2015 +0000
- Revision:
- 0:e1d95cf9daa8
- Child:
- 1:e21d7c0748cf
First;
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 | 0:e1d95cf9daa8 | 3 | PwmOut servo(PWM_OUT); |
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 | 0:e1d95cf9daa8 | 10 | servo.period_us(20000); // servo requires a 20ms period |
spin7ion | 0:e1d95cf9daa8 | 11 | servo.pulsewidth_us(servopulsewidth); |
spin7ion | 0:e1d95cf9daa8 | 12 | wait(2); |
spin7ion | 0:e1d95cf9daa8 | 13 | while (1) { |
spin7ion | 0:e1d95cf9daa8 | 14 | servopulsewidth+=signer; |
spin7ion | 0:e1d95cf9daa8 | 15 | |
spin7ion | 0:e1d95cf9daa8 | 16 | if(signer>0 && servopulsewidth>1990) |
spin7ion | 0:e1d95cf9daa8 | 17 | signer=-1; |
spin7ion | 0:e1d95cf9daa8 | 18 | }else if(signer<0 && servopulsewidth<10){ |
spin7ion | 0:e1d95cf9daa8 | 19 | signer=1; |
spin7ion | 0:e1d95cf9daa8 | 20 | } |
spin7ion | 0:e1d95cf9daa8 | 21 | servo.pulsewidth_us(servopulsewidth); |
spin7ion | 0:e1d95cf9daa8 | 22 | wait(0.25); |
spin7ion | 0:e1d95cf9daa8 | 23 | } |
spin7ion | 0:e1d95cf9daa8 | 24 | } |