-
Notifications
You must be signed in to change notification settings - Fork 1
/
gpiotest.cpp
100 lines (66 loc) · 1.93 KB
/
gpiotest.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//#include "i2cdevice.h"
#include "GPIO.h"
//#include<iostream>
#define RightMotor_EnablePin 67
#define RightMotor_ForwardPin 68
#define RightMotor_BackwardPin 44
#define LeftMotor_EnablePin 26
#define LeftMotor_ForwardPin 46
#define LeftMotor_BackwardPin 65
#define I2C_bus 0
#define I2C_device 0
using namespace exploringBB;
GPIO RM_EN(RightMotor_EnablePin); //RM_EN.setDirection(OUTPUT); RM_EN.setValue(HIGH);
GPIO RM_FW(RightMotor_ForwardPin); //RM_FW.setDirection(OUTPUT); RM_FW.setValue(LOW);
GPIO RM_BW(RightMotor_BackwardPin); //RM_BW.setDirection(OUTPUT); RM_BW.setValue(LOW);
GPIO LM_EN(LeftMotor_EnablePin); //LM_EN.setDirection(OUTPUT); LM_EN.setValue(HIGH);
GPIO LM_FW(LeftMotor_ForwardPin); //LM_FW.setDirection(OUTPUT); LM_FW.setValue(LOW);
GPIO LM_BW(LeftMotor_BackwardPin); //LM_BW.setDirection(OUTPUT); LM_BW.setValue(LOW);
void stopmotors(){
RM_FW.setValue(LOW);
LM_FW.setValue(LOW);
RM_BW.setValue(LOW);
LM_BW.setValue(LOW);
}
void forward(){
//1. stop backward movement
stopmotors();
//2. move forward
RM_FW.setValue(HIGH);
LM_FW.setValue(HIGH);
}
void backward(){
//1. stop forward movement
stopmotors();
//2. move backward
RM_BW.setValue(HIGH);
LM_BW.setValue(HIGH);
}
void right(){
stopmotors();
LM_FW.setValue(HIGH);
//RM_BW.setValue(HIGH);
}
void left(){
stopmotors();
RM_FW.setValue(HIGH);
//LM_BW.setValue(HIGH);
}
void readall(){
}
int main(){
//1. setup motors
while(1){
RM_EN.setDirection(OUTPUT); RM_EN.setValue(HIGH);
RM_FW.setDirection(OUTPUT); RM_FW.setValue(LOW);
RM_BW.setDirection(OUTPUT); RM_BW.setValue(LOW);
LM_EN.setDirection(OUTPUT); LM_EN.setValue(HIGH);
LM_FW.setDirection(OUTPUT); LM_FW.setValue(LOW);
LM_BW.setDirection(OUTPUT); LM_BW.setValue(LOW);
}
//2. initialise I2C device
//I2CDevice MPU6050(I2C_bus,I2C_device);
//MPU6050.writeRegister(0x6B,0x00); //disable sleep mode of MPU6050
//3. implement PID
return 0;
}