-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheel.h
53 lines (45 loc) · 1.13 KB
/
wheel.h
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Developed by Saad Bin Khalid
// Contact : k200161@nu.edu.pk
#ifndef WHEEL_H
#define WHEEL_H
class Wheel
{
const unsigned dir1; // direction pin#1
const unsigned dir2; // direction pin#2
const unsigned controlPin; // speed control pin
public:
// constructor:
Wheel(const unsigned &Dir1, const unsigned &Dir2, const unsigned &ControlPin)
: dir1(Dir1), dir2(Dir2), controlPin(ControlPin)
{
// setting pins on output mode
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);
pinMode(controlPin, OUTPUT);
// initialy, the wheel is stopped
digitalWrite(dir1, LOW);
digitalWrite(dir2, LOW);
}
// move the wheel in forward direction
void forward(const unsigned& Speed)
{
digitalWrite(dir1, HIGH);
digitalWrite(dir2, LOW);
analogWrite(controlPin, Speed);
}
// move the wheel in backward direction
void backward(const unsigned& Speed)
{
digitalWrite(dir1, LOW);
digitalWrite(dir2, HIGH);
analogWrite(controlPin, Speed);
}
// stop the wheel
void Stop()
{
digitalWrite(dir1, LOW);
digitalWrite(dir2, LOW);
analogWrite(controlPin, 0);
}
};
#endif