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.
main.cpp@0:8ba886befbee, 2018-10-28 (annotated)
- Committer:
- Sraddha
- Date:
- Sun Oct 28 14:17:00 2018 +0000
- Revision:
- 0:8ba886befbee
aaa
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Sraddha | 0:8ba886befbee | 1 | #Control Servo position with PWM |
| Sraddha | 0:8ba886befbee | 2 | |
| Sraddha | 0:8ba886befbee | 3 | #include "mbed.h" |
| Sraddha | 0:8ba886befbee | 4 | PwmOut servo(p7); |
| Sraddha | 0:8ba886befbee | 5 | int main() { |
| Sraddha | 0:8ba886befbee | 6 | for(float i = 0; i <= 1; i = i + 0.25) |
| Sraddha | 0:8ba886befbee | 7 | { |
| Sraddha | 0:8ba886befbee | 8 | servo = i; |
| Sraddha | 0:8ba886befbee | 9 | wait(0.02); |
| Sraddha | 0:8ba886befbee | 10 | } |
| Sraddha | 0:8ba886befbee | 11 | while(1); |
| Sraddha | 0:8ba886befbee | 12 | } |
| Sraddha | 0:8ba886befbee | 13 | |
| Sraddha | 0:8ba886befbee | 14 | #LDR |
| Sraddha | 0:8ba886befbee | 15 | |
| Sraddha | 0:8ba886befbee | 16 | #include "mbed.h" |
| Sraddha | 0:8ba886befbee | 17 | DigitalOut myled(LED1); |
| Sraddha | 0:8ba886befbee | 18 | AnalogIn ldr(p20); |
| Sraddha | 0:8ba886befbee | 19 | Serial pc(USBTX, USBRX); |
| Sraddha | 0:8ba886befbee | 20 | PwmOut servo(p5); |
| Sraddha | 0:8ba886befbee | 21 | int main() { |
| Sraddha | 0:8ba886befbee | 22 | servo.period_ms(20); |
| Sraddha | 0:8ba886befbee | 23 | while(1) |
| Sraddha | 0:8ba886befbee | 24 | { pc.printf("%.2f\n\r", ldr*180); |
| Sraddha | 0:8ba886befbee | 25 | servo.pulsewidth_us(1500+ldr*1500); |
| Sraddha | 0:8ba886befbee | 26 | wait(0.1); |
| Sraddha | 0:8ba886befbee | 27 | } |
| Sraddha | 0:8ba886befbee | 28 | } |