Motor Shield Example code for 2.74 Class @ MIT
Dependents: experiment_example motor_shield_example Lab3_experiment_example jumping_leg_clicky
MotorShield.h@0:f2ede00aed8a, 2020-08-24 (annotated)
- Committer:
- elijahsj
- Date:
- Mon Aug 24 20:19:03 2020 +0000
- Revision:
- 0:f2ede00aed8a
- Child:
- 1:4c3c2b7337a6
Initial class structure;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elijahsj | 0:f2ede00aed8a | 1 | /* Library to interface with 2.74 Motor Shield |
elijahsj | 0:f2ede00aed8a | 2 | ** Uses a modified version of FastPWM library to improve PWM accuracy |
elijahsj | 0:f2ede00aed8a | 3 | */ |
elijahsj | 0:f2ede00aed8a | 4 | |
elijahsj | 0:f2ede00aed8a | 5 | #include "FastPWM.h" |
elijahsj | 0:f2ede00aed8a | 6 | |
elijahsj | 0:f2ede00aed8a | 7 | class MotorShield { |
elijahsj | 0:f2ede00aed8a | 8 | |
elijahsj | 0:f2ede00aed8a | 9 | public: |
elijahsj | 0:f2ede00aed8a | 10 | |
elijahsj | 0:f2ede00aed8a | 11 | /** Receives two PinName variables. |
elijahsj | 0:f2ede00aed8a | 12 | * @param echoPin mbed pin to which the echo signal is connected to |
elijahsj | 0:f2ede00aed8a | 13 | * @param triggerPin mbed pin to which the trigger signal is connected to |
elijahsj | 0:f2ede00aed8a | 14 | */ |
elijahsj | 0:f2ede00aed8a | 15 | MotorShield(PinName forwardPin, PinName reversePin); |
elijahsj | 0:f2ede00aed8a | 16 | |
elijahsj | 0:f2ede00aed8a | 17 | /** Calculates the distance in cm, with the calculation time of 25 ms. |
elijahsj | 0:f2ede00aed8a | 18 | * @returns distance of the measuring object in cm. |
elijahsj | 0:f2ede00aed8a | 19 | */ |
elijahsj | 0:f2ede00aed8a | 20 | void write(double duty_cycle); |
elijahsj | 0:f2ede00aed8a | 21 | void period(double period); |
elijahsj | 0:f2ede00aed8a | 22 | void direction(int direction); |
elijahsj | 0:f2ede00aed8a | 23 | |
elijahsj | 0:f2ede00aed8a | 24 | private: |
elijahsj | 0:f2ede00aed8a | 25 | |
elijahsj | 0:f2ede00aed8a | 26 | int direction_val; |
elijahsj | 0:f2ede00aed8a | 27 | double duty_cycle_val; |
elijahsj | 0:f2ede00aed8a | 28 | double period_val; |
elijahsj | 0:f2ede00aed8a | 29 | |
elijahsj | 0:f2ede00aed8a | 30 | void init(); |
elijahsj | 0:f2ede00aed8a | 31 | void writePWM(); |
elijahsj | 0:f2ede00aed8a | 32 | }; |
elijahsj | 0:f2ede00aed8a | 33 |