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.
Revision 0:2cedfd753855, committed 2020-08-02
- Comitter:
- Makoppe
- Date:
- Sun Aug 02 13:34:15 2020 +0000
- Commit message:
- a;
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 Sun Aug 02 13:34:15 2020 +0000
@@ -0,0 +1,55 @@
+#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));
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Aug 02 13:34:15 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file