Updated for the next revision of the motor board
MotorShield.cpp
- Committer:
- elijahsj
- Date:
- 2020-08-24
- Revision:
- 0:f2ede00aed8a
- Child:
- 1:4c3c2b7337a6
File content as of revision 0:f2ede00aed8a:
/* Library to interface with 2.74 Motor Shield ** Uses a modified version of FastPWM library to improve PWM accuracy */ #include "mbed.h" #include "MotorShield.h" #include "FastPWM.h" MotorShield::MotorShield(PinName forwardPin, PinName reversePin) { FastPWM forward(forwardPin, 1); FastPWM reverse(reversePin, 1); init(); } void MotorShield::init() { /** Initial config for the STM32H743 **/ direction_val = 0; duty_cycle_val = 0; period_val = 10.0; } void MotorShield::write(double duty_cycle) { duty_cycle_val = duty_cycle; writePWM(); } void MotorShield::period(double period) { period_val = period; writePWM(); } void MotorShield::direction(int direction) { direction_val = direction; writePWM(); } void MotorShield::writePWM(){ if (direction_val == 0){ forward.period_us(period_val); forward.write(duty_cycle_val); reverse.period_us(period_val); reverse.write(0); } else{ reverse.period_us(period_val); reverse.write(duty_cycle_val); forward.period_us(period_val); forward.write(0); } }