p kj
/
MKS22-CubeFine
LPC824
Fork of CubeFine by
Microduino_Motor.h@0:362c1482232c, 2016-06-02 (annotated)
- Committer:
- lixianyu
- Date:
- Thu Jun 02 04:03:31 2016 +0000
- Revision:
- 0:362c1482232c
- Child:
- 2:7964622fb5a5
work fine.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lixianyu | 0:362c1482232c | 1 | #ifndef Motor_h |
lixianyu | 0:362c1482232c | 2 | #define Motor_h |
lixianyu | 0:362c1482232c | 3 | |
lixianyu | 0:362c1482232c | 4 | //#include "Arduino.h" |
lixianyu | 0:362c1482232c | 5 | #include "mbed.h" |
lixianyu | 0:362c1482232c | 6 | |
lixianyu | 0:362c1482232c | 7 | #define CHAN_LEFT 0 |
lixianyu | 0:362c1482232c | 8 | #define CHAN_RIGHT 1 |
lixianyu | 0:362c1482232c | 9 | |
lixianyu | 0:362c1482232c | 10 | #if 0 |
lixianyu | 0:362c1482232c | 11 | typedef struct { |
lixianyu | 0:362c1482232c | 12 | uint8_t nbr_A :6 ; |
lixianyu | 0:362c1482232c | 13 | uint8_t nbr_B :6 ; |
lixianyu | 0:362c1482232c | 14 | } MotorPin_t; |
lixianyu | 0:362c1482232c | 15 | #else |
lixianyu | 0:362c1482232c | 16 | typedef struct { |
lixianyu | 0:362c1482232c | 17 | PinName nbr_A; |
lixianyu | 0:362c1482232c | 18 | PinName nbr_B; |
lixianyu | 0:362c1482232c | 19 | } MotorPin_t; |
lixianyu | 0:362c1482232c | 20 | |
lixianyu | 0:362c1482232c | 21 | #endif |
lixianyu | 0:362c1482232c | 22 | |
lixianyu | 0:362c1482232c | 23 | typedef struct { |
lixianyu | 0:362c1482232c | 24 | MotorPin_t Pin; |
lixianyu | 0:362c1482232c | 25 | } motor_t; |
lixianyu | 0:362c1482232c | 26 | |
lixianyu | 0:362c1482232c | 27 | class Motor |
lixianyu | 0:362c1482232c | 28 | { |
lixianyu | 0:362c1482232c | 29 | public: |
lixianyu | 0:362c1482232c | 30 | Motor(PinName _motor_pinA, PinName _motor_pinB); |
lixianyu | 0:362c1482232c | 31 | void Fix(float _fix); |
lixianyu | 0:362c1482232c | 32 | void Driver(int16_t _motor_driver); |
lixianyu | 0:362c1482232c | 33 | void Free(); |
lixianyu | 0:362c1482232c | 34 | void Brake(); |
lixianyu | 0:362c1482232c | 35 | int16_t GetData(int16_t _throttle, int16_t _steering, uint8_t _dir); |
lixianyu | 0:362c1482232c | 36 | private: |
lixianyu | 0:362c1482232c | 37 | uint8_t motorIndex; // index into the channel data for this key |
lixianyu | 0:362c1482232c | 38 | float fix; |
lixianyu | 0:362c1482232c | 39 | int16_t _motor_vol; |
lixianyu | 0:362c1482232c | 40 | protected: |
lixianyu | 0:362c1482232c | 41 | pwmout_t _pwmA; |
lixianyu | 0:362c1482232c | 42 | pwmout_t _pwmB; |
lixianyu | 0:362c1482232c | 43 | int _period_us; |
lixianyu | 0:362c1482232c | 44 | }; |
lixianyu | 0:362c1482232c | 45 | |
lixianyu | 0:362c1482232c | 46 | #endif |