Motor Shield Example code for 2.74 Class @ MIT

Dependents:   experiment_example motor_shield_example Lab3_experiment_example jumping_leg_clicky

Revision:
0:f2ede00aed8a
Child:
1:4c3c2b7337a6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MotorShield.h	Mon Aug 24 20:19:03 2020 +0000
@@ -0,0 +1,33 @@
+/* Library to interface with 2.74 Motor Shield
+** Uses a modified version of FastPWM library to improve PWM accuracy 
+*/
+
+#include "FastPWM.h"
+
+class MotorShield {
+    
+    public:
+    
+    /** Receives two PinName variables.
+     * @param echoPin mbed pin to which the echo signal is connected to
+     * @param triggerPin mbed pin to which the trigger signal is connected to
+     */
+    MotorShield(PinName forwardPin, PinName reversePin);
+    
+    /** Calculates the distance in cm, with the calculation time of 25 ms.
+     * @returns distance of the measuring object in cm.
+     */
+    void write(double duty_cycle);
+    void period(double period);
+    void direction(int direction);
+    
+    private:
+    
+    int direction_val;
+    double duty_cycle_val;
+    double period_val;
+    
+    void init();
+    void writePWM();
+};
+