-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI2C_slave.ino
More file actions
53 lines (44 loc) · 828 Bytes
/
Copy pathI2C_slave.ino
File metadata and controls
53 lines (44 loc) · 828 Bytes
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
#include <Wire.h>
#define I2C_SLAVE_ADRESS 11
int instruction = 0;
void setup()
{
Wire.begin(I2C_SLAVE_ADRESS);
Serial.begin(57600);
Serial.println(I2C_SLAVE_ADRESS);
Serial.print(" is a slave");
}
void loop()
{
Wire.onRequest(requestEvents);
Wire.onReceive(receiveEvents);
test();
}
int requestEvents()
{
Serial.println("--< Request receive");
Wire.write("Ok");
}
int receiveEvents()
{
Serial.println("-->Instruction receive");
instruction = Wire.read();
}
//Code ici
int test()
{
if (instruction == 1)
{
Serial.println("DOOOOOOOOOOOONE");
}
else if (instruction == 0)
{
Serial.println("Fondamental state");
}
else
{
Serial.println("Instruction = ");
Serial.print(instruction);
}
delay(500);
}