-
Notifications
You must be signed in to change notification settings - Fork 0
/
FolkRace.ino
186 lines (156 loc) · 3.27 KB
/
FolkRace.ino
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//#include "funkcje.h"
#include <SoftWire.h>
#include <vl53l0x_class.h>
//SILNIKI
#define L1 PB8
#define L2 PB9
#define R1 PB7
#define R2 PB6
#define L 0
#define R 1
int prevmili=millis();
//RGB
#define R PA3
#define G PA2
#define B PA1
//VL53L0X
#define SCL PB10
#define SDA PB11
#define XSHUTL PB12
#define XSHUTM PB14
#define XSHUTR PA8
#define GPIOL PB13
#define GPIOM PB15
#define GPIOR PA9
//IR
#define IRL PB0
#define IRR PB1
//BATERIA
#define BAT PA7
//START
#define START PB4
//PROGI
#define batThreshold 2137
#define irThreshold 1500
#define vlThreshold 600
#define halfPeriod 500
//FLAGI
bool rBlinking = false;
int rState = LOW;
int STATE = 0;
bool DIR = 1;
bool TIMEOUT = 0;
int ind=0;
int lLine;
int rLine;
int v= 50;
int timing=0;
bool strona=true;
//CZASY
uint32_t rPrevMillis = 0;
uint32_t prevMillis = 0;
int timeLeft = 0;
#define TURN 500;
#define SCAN 1000;
#define RETREAT 300;
SoftWire WIRE1(PB10, PB11, SOFT_FAST);
VL53L0X sensorL(&WIRE1, XSHUTL, GPIOL); //WIRE, XSHUT, INT
VL53L0X sensorM(&WIRE1, XSHUTM, GPIOM);
VL53L0X sensorR(&WIRE1, XSHUTR, GPIOR);
uint32_t distanceL;
uint32_t distanceM;
uint32_t distanceR;
bool kontra=false;
void setup()
{
//PWM
pinMode(L1, PWM);
pinMode(L2, PWM);
pinMode(R1, PWM);
pinMode(R2, PWM);
//DIGITAL
pinMode(PC13, OUTPUT);
pinMode(R, OUTPUT);
pinMode(G, OUTPUT);
pinMode(B, OUTPUT);
//ANALOG
//VL53L0X
int status;
Serial.begin(9600);
WIRE1.begin();
sensorL.VL53L0X_Off();
sensorM.VL53L0X_Off();
sensorR.VL53L0X_Off();
status = sensorL.InitSensor(0x10);
//sensorL.VL53L0X_Off();
while(status)
{
digitalWrite(R,HIGH);
digitalWrite(G,HIGH);
digitalWrite(B,HIGH);
delay(500);
digitalWrite(R,LOW);
delay(500);
Serial.println("L Init sensor_vl53l0x failed...");
}
delay(150);
status = sensorR.InitSensor(0x18);
//sensorR.VL53L0X_Off();
while(status)
{
digitalWrite(R,HIGH);
digitalWrite(G,HIGH);
digitalWrite(B,HIGH);
delay(500);
digitalWrite(R,LOW);
delay(500);
Serial.println("R Init sensor_vl53l0x failed...");
}
delay(150);
status = sensorM.InitSensor(0x26);
while(status)
{
digitalWrite(R,HIGH);
digitalWrite(G,HIGH);
digitalWrite(B,HIGH);
delay(500);
digitalWrite(R,LOW);
delay(500);
Serial.println("M Init sensor_vl53l0x failed...");
}
digitalWrite(R, LOW);
digitalWrite(G, LOW);
digitalWrite(B, LOW);
DIR = analogRead(IRL) % 2;
digitalWrite(R, HIGH);
digitalWrite(G, HIGH);
digitalWrite(B, HIGH);
while(millis()<5000){}
power(L,0,70);
power(R,0,70);
delay(100);
}
/////////////////////////////////////////////////////////////////////////////////////////LOOP
void loop()
{
int rng=350;
sensorL.GetDistance(&distanceL);
sensorM.GetDistance(&distanceM);
sensorR.GetDistance(&distanceR);
//lLine = analogRead(IRL);
//rLine = analogRead(IRL);
Serial.print(distanceL);
Serial.print(" ");
Serial.print(distanceM);
Serial.print(" ");
Serial.println(distanceR);
if(distanceL==0){
distanceL=2600;
}
if(distanceM==0){
distanceM=2600;
}
if(distanceR==0){
distanceR=2600;
}
}