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:0add14ba6212
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Dec 30 08:55:35 2019 +0000
@@ -0,0 +1,52 @@
+//==================================================
+//Servo
+//
+//MPU board: mbed LPC1768
+//2019/11/17 A.Toda
+//==================================================
+#include "mbed.h"
+
+//==================================================
+#define SERVO_PERIOD 0.020
+//==================================================
+
+//Port Setting
+
+PwmOut ELE(p21);
+Serial pc(USBTX, USBRX); //UART
+
+//==================================================
+//Timer valiables
+//==================================================
+
+double pulse_width_ele;
+
+//==================================================
+//Main
+//==================================================
+int main() {
+
+ //UART initialization
+ pc.baud(115200);
+
+ //define servo period
+ ELE.period(SERVO_PERIOD); // servo requires 20ms period
+ pulse_width_ele=0.6/1000.0;
+
+ //while
+ while(1) {
+
+ // servo position determined by a pulsewidth between 0.6-2.4ms
+
+ for(int i=0;i<18;i++){
+ pulse_width_ele += ( 0.1/1000.0 );
+ ELE.pulsewidth(pulse_width_ele);
+ pc.printf("Pulse width is %f\r\n",pulse_width_ele);
+ wait(1.0);
+ }
+
+ pulse_width_ele=0.6/1000.0;
+
+ }//while ends
+
+}//main ends
\ No newline at end of file