Smartcar Shield
Loading...
Searching...
No Matches
BrushedMotor.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include <stdint.h> // NOLINT(modernize-deprecated-headers)
13
14#include "../../../runtime/Runtime.hpp"
15#include "../../Motor.hpp"
16
21{
29 BrushedMotorPins(uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin)
30 : forward{ forwardPin }
31 , backward{ backwardPin }
32 , enable{ enablePin }
33 {
34 }
35
36 const uint8_t forward; // NOLINT: It's OK for these to be public
37 const uint8_t backward; // NOLINT
38 const uint8_t enable; // NOLINT
39};
40
41class BrushedMotor : public Motor
42{
43public:
57 BrushedMotor(Runtime& runtime, uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin);
58
71
72 /* Check `Motor` interface for documentation */
73 void setSpeed(int speed) override;
74
75private:
76 void attach();
77 const uint8_t kForwardPin;
78 const uint8_t kBackwardPin;
79 const uint8_t kEnablePin;
80 Runtime& mRuntime;
81 const uint8_t kOutput;
82 const uint8_t kLow;
83 const uint8_t kHigh;
84 bool mAttached{ false };
85};
A brushed motor is controlled via two wires where the flow of current determines the direction of rot...
void setSpeed(int speed) override
Sets the motor speed and direction as the percentage of the maximum possible speed,...
Interface programmatically representing any kind of motor.
Definition Motor.hpp:23
An interface to serve as a wrapper for the native runtime environment, greatly inspired by the Arduin...
Definition Runtime.hpp:36
Helper class to represent brushed motor pins.
BrushedMotorPins(uint8_t forwardPin, uint8_t backwardPin, uint8_t enablePin)
Construct a BrushedMotorPins object.
const uint8_t enable
const uint8_t backward
const uint8_t forward