-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobots.ino
87 lines (83 loc) · 1.79 KB
/
robots.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
#include <EEPROM.h>
#include <Wire.h>
#define _DEBUG
#ifdef _DEBUG
#define DP(x) \
Serial.print(x);
#define DPln(x) \
Serial.println(x)
#endif // _DEBUG
/*
ESP
i2c pins
SDA 21
SCL 22
EV3
white->none
black->none
red->GND
green->vcc
yellow->SCL
blue->SDA
*/
constexpr uint8_t red = 32;
constexpr uint8_t green = 26;
constexpr uint8_t blue = 25;
constexpr uint8_t light1 = 15;
constexpr uint8_t light2 = 4;
constexpr uint8_t light3 = 34;
constexpr uint8_t light4 = 35;
constexpr uint8_t light5 = 12;
constexpr uint8_t light6 = 27;
constexpr uint8_t light7 = 14;
constexpr uint8_t waittime=600;
inline void lightup(uint8_t r, uint8_t g, uint8_t b);
inline void i2cSendEvent();
uint8_t colordata[7][3];
#define getdata(x) \
colordata[0][x]=analogRead(light1); \
colordata[1][x]=analogRead(light2); \
colordata[2][x]=analogRead(light3); \
colordata[3][x]=analogRead(light4); \
colordata[4][x]=analogRead(light5); \
colordata[5][x]=analogRead(light6); \
colordata[6][x]=analogRead(light7);
void setup() {
#ifdef _DEBUG
Serial.begin(115200);
Serial.println("serial start");
#endif
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(light1, INPUT);
pinMode(light2, INPUT);
pinMode(light3, INPUT);
pinMode(light4, INPUT);
pinMode(light5, INPUT);
pinMode(light6, INPUT);
pinMode(light7, INPUT);
Wire.onRequest(i2cSendEvent);
}
void loop() {
DPln("RED");
lightup(HIGH, LOW, LOW);
getdata(0);
delay(waittime);
DPln("GREEN");
lightup(LOW, HIGH, LOW);
getdata(1)
delay(waittime);
DPln("BLUE");
lightup(LOW, LOW, HIGH);
getdata(2);
delay(waittime);
}
inline void lightup(uint8_t r, uint8_t g, uint8_t b){
digitalWrite(red, r);
digitalWrite(green, g);
digitalWrite(blue, b);
}
inline void i2cSendEvent(){
Wire.write(colordata, sizeof(colordata));
}