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.
Fork of Motor by
Motor.cpp
00001 /** 00002 * Includes 00003 */ 00004 #include "Motor.h" 00005 Motor::Motor(const Motor& m): 00006 mode(m.Pin[0],m.Pin[1]),PwmPin(m.Pin[2]) 00007 { 00008 bias=0.0; 00009 max=m.max; 00010 //this 00011 PwmPin.period_ms(20); 00012 run(Stop,1); 00013 } 00014 00015 Motor::Motor(PinName _pin1, PinName _pin2,PinName _pwm) : 00016 mode(_pin1,_pin2),PwmPin(_pwm) 00017 { 00018 Pin[0] = _pin1; 00019 Pin[1] = _pin2; 00020 Pin[2] = _pwm; 00021 max=1.0; 00022 //this 00023 PwmPin.period_ms(10); 00024 run(Stop,1); 00025 } 00026 void Motor::run(int i,float duty) 00027 { 00028 //static int state; 00029 Duty = (float)duty*max+bias; 00030 //printf("Duty %f \n",(float)duty); 00031 //if(state==i)return; 00032 PwmPin = Duty; 00033 if(state==i)return; 00034 mode=0; 00035 wait_us(20); 00036 if(i==Free) mode=0x00; 00037 else if(i==Back) mode=0x01|0x00; 00038 else if(i==Front) mode=0x00|0x02; 00039 else if(i==Stop) mode=0x01|0x02; 00040 else mode=0x00; 00041 state=i; 00042 } 00043 00044 00045 00046
Generated on Fri Jul 15 2022 19:58:09 by
1.7.2
