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
Diff: main.cpp
- Revision:
- 1:8c73948a0864
- Parent:
- 0:fd080fb55bae
- Child:
- 2:bf817b299c19
diff -r fd080fb55bae -r 8c73948a0864 main.cpp
--- a/main.cpp Tue Oct 06 22:09:22 2015 +0000
+++ b/main.cpp Thu Oct 08 19:56:17 2015 +0000
@@ -1,8 +1,26 @@
+/*
+Using pwm to run a servo motor
+Connect the red wire of the servo motor to 3.3V and not 5V
+*/
#include "mbed.h"
PwmOut pwm1(p21);
+Serial pc(USBTX, USBRX);
int main() {
pwm1.period_ms(20);
- pwm1.write(0.5);
+
+ while(1){
+ char c = pc.getc();
+ if(c=='1'){
+ pwm1.write(0);
+ wait(0.5);
+ pwm1.write(0.0375); // 3.75% duty cycle - Open the gate
+ }
+ else{
+ pwm1.write(0);
+ wait(0.5);
+ pwm1.write(0.1125); // 11.25% duty cycle - Close the gate
+ }
+ }
return 0;
}