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
- Committer:
- Sraddha
- Date:
- 2018-10-28
- Revision:
- 0:8ba886befbee
File content as of revision 0:8ba886befbee:
#Control Servo position with PWM
#include "mbed.h"
PwmOut servo(p7);
int main() {
for(float i = 0; i <= 1; i = i + 0.25)
{
servo = i;
wait(0.02);
}
while(1);
}
#LDR
#include "mbed.h"
DigitalOut myled(LED1);
AnalogIn ldr(p20);
Serial pc(USBTX, USBRX);
PwmOut servo(p5);
int main() {
servo.period_ms(20);
while(1)
{ pc.printf("%.2f\n\r", ldr*180);
servo.pulsewidth_us(1500+ldr*1500);
wait(0.1);
}
}