-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWheel.cpp
More file actions
36 lines (29 loc) · 736 Bytes
/
Wheel.cpp
File metadata and controls
36 lines (29 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Arduino.h"
#include "Wheel.h"
Wheel::Wheel(int enable, int inHigh, int inLow) {
this->enable = enable;
this->inHigh = inHigh;
this->inLow = inLow;
pinMode(enable, OUTPUT);
pinMode(inHigh, OUTPUT);
pinMode(inLow, OUTPUT);
stop();
setSpeed(default_speed);
}
void Wheel::setSpeed(int speed) {
analogWrite(this->enable, speed);
}
void Wheel::forward(int speed) {
setSpeed(speed);
digitalWrite(this->inHigh, HIGH);
digitalWrite(this->inLow, LOW);
}
void Wheel::backward(int speed) {
setSpeed(speed);
digitalWrite(this->inHigh, LOW);
digitalWrite(this->inLow, HIGH);
}
void Wheel::stop() {
digitalWrite(this->inHigh, LOW);
digitalWrite(this->inLow, LOW);
}