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.
main.cpp
- Committer:
- Makoppe
- Date:
- 2020-08-02
- Revision:
- 0:2cedfd753855
File content as of revision 0:2cedfd753855:
#include "mbed.h"
AnalogIn IN(A0);
DigitalOut MotorP(D2);
DigitalOut MotorM(D3);
int main() {
double InVal;
double AbsVal;
int PwmPeriod=420;//423
while(1) {
InVal=IN.read();
InVal=((InVal-0.5)*2.0);
AbsVal=fabs(InVal);
PwmPeriod=3325; //
if(AbsVal>0.9){ //
PwmPeriod=3325;
}else if(AbsVal>0.8){
PwmPeriod=1640;
}else if(AbsVal>0.16){
PwmPeriod=1050;
}else if(AbsVal>0.11){ //
PwmPeriod=1640;
}else if(AbsVal>0.06){
PwmPeriod=3325;
}else if(AbsVal>0.01){
PwmPeriod=6663;
}
//printf("%f ",InVal);
if(InVal>0){
MotorP=1;
MotorM=0;
wait_us(PwmPeriod*InVal);
MotorP=0;
MotorM=0;
wait_us(PwmPeriod-PwmPeriod*InVal);
}else if(InVal<0){
MotorP=0;
MotorM=1;
wait_us(PwmPeriod*-InVal);
MotorP=0;
MotorM=0;
wait_us(PwmPeriod-PwmPeriod*-InVal);
}else{
MotorP=0;
MotorM=0;
wait_us(PwmPeriod);
}
//printf("%d\n\r",(int)(PwmPeriod*InVal));
}
}