-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
54 lines (47 loc) · 1.09 KB
/
main.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
#include<Arduino.h>
#include<Wire.h>
uint8_t LED = 13;
uint8_t addr= 1;
bool addressset = false;
void onreceive3(){
Serial.println("hi again");
}
void onreceive2(){
Serial.println(addr);
}
void receiveEvent(int bytes) {
//digitalWrite(LED,HIGH);
if(digitalRead(7)==LOW){
//
Serial.println(addr);
Wire.write(0);
//Serial.print("my addr:");
Wire.onReceive(onreceive2);
}else{
addr++;
Wire.begin(addr);
Wire.onReceive(receiveEvent);
}
}
void setup(){
pinMode (LED, OUTPUT);
digitalWrite(LED,LOW);
digitalWrite(LED,HIGH);
delay(10);
digitalWrite(LED,LOW);
pinMode(7,INPUT);
Wire.begin(addr);
Wire.onReceive(receiveEvent);
Serial.begin(115200);
}
void loop(){
if(Serial.available()>0){
Wire.begin();
Wire.beginTransmission(0x7F);
const char buff[] = {0x02,0x02,0x20+(Serial.read()-'0')};
Wire.write(buff,3);
Wire.endTransmission();
Wire.begin(addr);
Wire.onReceive(onreceive3);
}
}