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:
- 3:8d07dbdd3afc
- Parent:
- 2:2cc5d274f30d
- Child:
- 4:f1782bdd08a8
--- a/main.cpp Fri Oct 21 13:33:35 2016 +0000
+++ b/main.cpp Mon Oct 24 08:22:45 2016 +0000
@@ -16,28 +16,28 @@
while (true) {
- if (pc.readable()) {
- Key = pc.getc();
+ if (pc.readable()) { // if a key press happens
+ Key = pc.getc(); // get the pressed key
switch(Key) { //Check to see which key pressed
- case 0x41: //It was the UP Key key...
- pc.printf("\n\r UP!");
+ case 0xBB: //It was the + key...
+ pc.printf("\n\r +!");
if( ServoAngle < 80){
- ServoAngle = ServoAngle+10;
+ ServoAngle = ServoAngle+10; // increase the angle
}
break;
- case 0x42: //It was the DOWN Key key...
- pc.printf("\n\r DOWN!");
+ case 0xBD: //It was the - Key key...
+ pc.printf("\n\r -!");
if( ServoAngle > 1){
- ServoAngle = ServoAngle-10;
+ ServoAngle = ServoAngle-10; // decrease the angle
}
break;
case 0x20: //It was the Spacebar key...
pc.printf("\n\r SPACE!");
if( ServoAngle < 45){ // Switch from open to closed or else otherwise
- ServoAngle = 89;
+ ServoAngle = 89; // open/close
}
else{
- ServoAngle = 1;
+ ServoAngle = 1; // open/close
}
break;
}
@@ -45,8 +45,8 @@
wait(1/Frequency);
}
- Pulsew = 0.0015+(ServoAngle)/180000;
- ServoPWMpin.pulsewidth(Pulsew); // write the dutycycle
+ Pulsew = 0.0015+(ServoAngle)/180000; // calculate the pulsewidth in the range 1 to 2 milliseconds
+ ServoPWMpin.pulsewidth(Pulsew); // write the pulsewidth
pc.printf("\n\r Pulsew is %f",Pulsew);
}
}
\ No newline at end of file