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.
motor.h@2:bc41daf2b0ce, 2018-12-17 (annotated)
- Committer:
- martinsimpson
- Date:
- Mon Dec 17 11:09:11 2018 +0000
- Revision:
- 2:bc41daf2b0ce
- Parent:
- 1:3ca91ad8e927
update to motor.h
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martinsimpson | 0:51c12cc34baf | 1 | #ifndef _MOTOR_H_ |
| martinsimpson | 0:51c12cc34baf | 2 | #define _MOTOR_H_ |
| martinsimpson | 0:51c12cc34baf | 3 | #include "mbed.h" |
| martinsimpson | 2:bc41daf2b0ce | 4 | |
| martinsimpson | 2:bc41daf2b0ce | 5 | namespace mbed { |
| martinsimpson | 2:bc41daf2b0ce | 6 | /** \addtogroup drivers */ |
| martinsimpson | 2:bc41daf2b0ce | 7 | |
| martinsimpson | 2:bc41daf2b0ce | 8 | /** A Motor Driver, used for setting the pins for PWM Outpu |
| martinsimpson | 2:bc41daf2b0ce | 9 | * for use with ROCO104 |
| martinsimpson | 2:bc41daf2b0ce | 10 | * |
| martinsimpson | 2:bc41daf2b0ce | 11 | * @note Synchronization level: Interrupt safe |
| martinsimpson | 2:bc41daf2b0ce | 12 | * |
| martinsimpson | 2:bc41daf2b0ce | 13 | * Example: |
| martinsimpson | 2:bc41daf2b0ce | 14 | * @code |
| martinsimpson | 2:bc41daf2b0ce | 15 | * // Toggle a LED |
| martinsimpson | 2:bc41daf2b0ce | 16 | * #include "mbed.h" |
| martinsimpson | 2:bc41daf2b0ce | 17 | * |
| martinsimpson | 2:bc41daf2b0ce | 18 | * Motor Wheels(D15,D14,D13,D12); |
| martinsimpson | 2:bc41daf2b0ce | 19 | * |
| martinsimpson | 2:bc41daf2b0ce | 20 | * int main() |
| martinsimpson | 2:bc41daf2b0ce | 21 | * { |
| martinsimpson | 2:bc41daf2b0ce | 22 | * Wheel.Period_in_ms(2);//Set frequency of the PWMs 500Hz |
| martinsimpson | 2:bc41daf2b0ce | 23 | * while(true) |
| martinsimpson | 2:bc41daf2b0ce | 24 | * { |
| martinsimpson | 2:bc41daf2b0ce | 25 | * Wheel.Speed(0.8,0.8);//Forward 80% |
| martinsimpson | 2:bc41daf2b0ce | 26 | * wait(5.0); |
| martinsimpson | 2:bc41daf2b0ce | 27 | * Wheel.stop(); |
| martinsimpson | 2:bc41daf2b0ce | 28 | * wait(1.0); |
| martinsimpson | 2:bc41daf2b0ce | 29 | * Wheel.Speed(-0.8,-0.8);//Reverse 80% |
| martinsimpson | 2:bc41daf2b0ce | 30 | * wait(5.0); |
| martinsimpson | 2:bc41daf2b0ce | 31 | * Wheel.stop(); |
| martinsimpson | 2:bc41daf2b0ce | 32 | * wait(1.0); |
| martinsimpson | 2:bc41daf2b0ce | 33 | * } |
| martinsimpson | 2:bc41daf2b0ce | 34 | * } |
| martinsimpson | 2:bc41daf2b0ce | 35 | * @endcode |
| martinsimpson | 2:bc41daf2b0ce | 36 | */ |
| martinsimpson | 2:bc41daf2b0ce | 37 | } // namespace mbed |
| martinsimpson | 2:bc41daf2b0ce | 38 | |
| martinsimpson | 0:51c12cc34baf | 39 | class Motor |
| martinsimpson | 0:51c12cc34baf | 40 | { |
| martinsimpson | 0:51c12cc34baf | 41 | public: |
| martinsimpson | 1:3ca91ad8e927 | 42 | Motor(PinName pinName1, PinName pinName2, PinName pinName3, PinName pinName4); |
| martinsimpson | 0:51c12cc34baf | 43 | void Fwd(float time); |
| martinsimpson | 0:51c12cc34baf | 44 | void Rev(float time); |
| martinsimpson | 1:3ca91ad8e927 | 45 | void Stop(void); |
| martinsimpson | 1:3ca91ad8e927 | 46 | int Speed(float speedA, float speedB); |
| martinsimpson | 0:51c12cc34baf | 47 | void Period_in_ms(int msPeriod); |
| martinsimpson | 0:51c12cc34baf | 48 | private: |
| martinsimpson | 0:51c12cc34baf | 49 | PwmOut pin1; |
| martinsimpson | 0:51c12cc34baf | 50 | PwmOut pin2; |
| martinsimpson | 1:3ca91ad8e927 | 51 | PwmOut pin3; |
| martinsimpson | 1:3ca91ad8e927 | 52 | PwmOut pin4; |
| martinsimpson | 0:51c12cc34baf | 53 | }; |
| martinsimpson | 1:3ca91ad8e927 | 54 | |
| martinsimpson | 1:3ca91ad8e927 | 55 | //int motor(float speedA, float speedB); |
| martinsimpson | 1:3ca91ad8e927 | 56 | |
| martinsimpson | 0:51c12cc34baf | 57 | #endif |