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.
Diff: main.cpp
- Revision:
- 0:ef8775413c37
- Child:
- 1:08bf7339efdd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Fri Oct 21 12:42:39 2016 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+
+Serial pc(USBTX,USBRX);
+
+PwmOut ServoPWMpin(D7);
+
+char Key;
+float ServoAngle = 0;
+float Pulsew = 0.0015;
+const float Frequency = 10;
+
+int main()
+{
+
+ ServoPWMpin.period(0.01f); // 0.01 second period
+
+ while (true) {
+
+ if (pc.readable()) {
+ Key = pc.getc();
+ switch(Key) { //Check to see which Key key...
+ case 0x41: //It was the UP Key key...
+ pc.printf("\n\r UP!");
+ if( ServoAngle < 90){
+ ServoAngle = ServoAngle+1;
+ }
+ break;
+ case 0x42: //It was the DOWN Key key...
+ pc.printf("\n\r DOWN!");
+ if( ServoAngle > -90){
+ ServoAngle = ServoAngle-1;
+ }
+ break;
+ case 0x20:
+ pc.printf("\n\r SPACE!");
+ if( ServoAngle == 0){
+ ServoAngle = 90;
+ }
+ else{
+ ServoAngle = -ServoAngle;
+ }
+ break;
+ }
+ }
+
+ wait(1/Frequency);
+ Pulsew = 0.0015+(ServoAngle)/180000;
+ ServoPWMpin.pulsewidth(Pulsew); // write the dutycycle
+ pc.printf("\n\r Pulsew is %f",Pulsew);
+ }
+}
\ No newline at end of file