arduino stuffs
Diffstat (limited to 'car_driver/arduino/motor_utils.h')
| -rw-r--r-- | car_driver/arduino/motor_utils.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/car_driver/arduino/motor_utils.h b/car_driver/arduino/motor_utils.h new file mode 100644 index 0000000..fea6441 --- /dev/null +++ b/car_driver/arduino/motor_utils.h @@ -0,0 +1,18 @@ +#ifndef MOTOR_UTILS_H +#define MOTOR_UTILS_H + +namespace motor_utils { +// @param direction LOW is backwards, HIGH is forward +// @param speed 0-255 +inline void set(int motor, int brake, int speed_pin, int direction, int speed) { + digitalWrite(motor, direction); + digitalWrite(brake, LOW); // brake off + analogWrite(speed_pin, speed); // speed up +} + +inline void brake(int brake_pin, int speed_pin) { + digitalWrite(brake_pin, HIGH); // engage brake + analogWrite(speed_pin, 0); // slow +} +} // namespace motor_utils +#endif
\ No newline at end of file |