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: MODSERIAL mbed-rtos mbed
Fork of Master by
control.cpp
- Committer:
- 9uS7
- Date:
- 2014-09-11
- Revision:
- 2:c610e1a7fbcd
- Parent:
- 1:e1cfb5850088
- Child:
- 3:12e1f116ea42
File content as of revision 2:c610e1a7fbcd:
#include "mbed.h" #include "control.h" //sensor AnalogIn IR(p17); AnalogIn FSR(p18); //motor DigitalOut Sig1(p21); DigitalOut Sig2(p23); PwmOut Pwm(p22); void motorSetup(void){ resetPos(); } void pull(float buf){ Sig1 = 0; Sig2 = 1; Pwm = zeroPWM+buf/3; } void loose(float buf){ Sig1 = 1; Sig2 = 0; Pwm = zeroPWM+buf/3; } void brake(void){ Sig1 = 0; Sig2 = 0; Pwm = 1; } void open(void){ Sig1 = 0; Sig2 = 0; Pwm = 0; } void resetPos(void){ int pos_flag=0; while(1){ if(IR>center_pos){ pull(0.3); }else if(IR<center_pos){ loose(0.3); } if(abs(IR-center_pos)<0.1){ open(); pos_flag=-1; } if(pos_flag) break; } }