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
Revision 0:0347fe0d0f32, committed 2016-02-12
- Comitter:
 - mfajaradityo
 - Date:
 - Fri Feb 12 10:02:09 2016 +0000
 - Commit message:
 - Control the speed of motor, connected to Servo Controller ESCON 36/2, through PWM and read the current drawn by the motor
 
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 | 
diff -r 000000000000 -r 0347fe0d0f32 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 12 10:02:09 2016 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+float dcPWM = 0;
+float iGRP = 0;
+
+AnalogIn grpControl(p15); //Analog Input to control Gripper-Motor's PWM
+AnalogIn grpCurrent(p16); //Analog Input to read Gripper-Motor's current
+InterruptIn check(p17); //Interrupt event to check Gripper-Motor's current
+
+PwmOut grpPWM(p30); //PWM Out for Gripper Motor
+
+//Check potensiometer voltage (GrpControl)
+//GrpControl analog read range [0.0f - 1.0f]
+//GrpPWM pwm out duty cycle range [0.1f - 0.9f]
+void updatePwmOut(AnalogIn analogPin, PwmOut *pwmPin) {
+    float dCycle = 0.1;
+    
+    dCycle += 0.8 * analogPin.read();
+    (*pwmPin).write(dCycle);
+         
+//End of updateGrpPWM()   
+}
+
+//Read the current of Brushed Motor RE-25 DC through Motor Controller ESCON 36/2
+//the current of Brushed Motor RE-25 DC range [(-3.0A) - (3.0A)]
+//GrpCurrent analog read range [0.0f - 0.1f]
+float readGrpCurrent(AnalogIn analogPin) {
+    float iReadOut = 0;
+    
+    iReadOut = (6 * analogPin.read()) - 3;
+    return iReadOut;
+    
+//End of readGrpCurrent   
+}
+
+void checkGrpCurrent() {    
+    iGRP = readGrpCurrent(grpCurrent);
+    pc.printf("Gripper-Motor's current : '%f'\n", iGRP);
+}
+
+int main() {
+    while(1) {
+        check.fall(&checkGrpCurrent);
+        updatePwmOut(grpControl, &grpPWM);
+        wait_ms(1);
+    }
+//End of main()    
+}
\ No newline at end of file
diff -r 000000000000 -r 0347fe0d0f32 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Feb 12 10:02:09 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32 \ No newline at end of file