AES-2015 / Mbed 2 deprecated cplusplus

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
BAC
Date:
Tue Nov 10 09:33:23 2015 +0000
Commit message:
C++ & class

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 10 09:33:23 2015 +0000
@@ -0,0 +1,40 @@
+#include "mbed.h"
+
+AnalogIn   F1p(PA_0); // Set PA_0 for ADC
+
+PwmOut M1(PA_6);      // Set PA_6 as LED output
+PwmOut LED(PA_5);     // Set PA_5 for driving RC servo
+
+// class declation
+class robotarm{
+public:
+       int readVR(void);      
+       void setpwmperiod(int);
+       void setpwmwidth(float);
+};
+
+// read voltage form VR
+int robotarm::readVR (void) {
+    return F1p;
+}
+// set period of PWM signal
+void robotarm::setpwmperiod(int p_ms){
+    M1.period_ms(p_ms);
+}
+// set pulse width of PWM signal
+void robotarm::setpwmwidth(float width){
+    M1.pulsewidth_us(width);
+} 
+     
+int main() {
+    
+    robotarm group1; // Define object
+
+    group1.setpwmperiod(20); // set period for PWM at pin PA_6 (defined in class)
+    LED.period_ms(20);       // set period for PWM at pin PA_5 (general case)
+    
+    while(1) {
+    group1.setpwmwidth(group1.readVR()*20000);  // set pulse width of PWM at pin PA_6 (defined in class)   
+    LED.pulsewidth_us(F1p*20000);               // set pulse width of PWM at pin PA_5 (general case)
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 10 09:33:23 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9296ab0bfc11
\ No newline at end of file