Arduino_lecture_capteurs.ino
2.19 KB
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
int firstSensor = 22;
int firstState = 0;
int secondSensor = 23;
int secondState = 0;
int thirdSensor = 24;
int thirdState = 0;
int fourthSensor = 25;
int fourthState = 0;
int fifthSensor = 26;
int fifthState = 0;
int sixthSensor = 27;
int sixthState = 0;
int seventhSensor = 28;
int seventhState = 0;
int eighthSensor = 29;
int eighthState = 0;
int tab[8];
void setup() { // Cette setup permet de définir la vitesse de communication des deux ports série, soit un 9600 BAUD.
// Elle permet également de mettre tous les pins utilisés par le programme en sortie
pinMode(firstSensor, INPUT);
pinMode(secondSensor, INPUT);
pinMode(thirdSensor, INPUT);
pinMode(fourthSensor, INPUT);
pinMode(fifthSensor, INPUT);
pinMode(sixthSensor, INPUT);
pinMode(seventhSensor, INPUT);
pinMode(eighthSensor, INPUT);
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() { //Cette boucle lit les valeurs des 8 capteurs, les met dans un tableau puis envoie chaque case du tableau par la liaison série.
int envoi = 0;
firstState = digitalRead(firstSensor);
secondState = digitalRead(secondSensor);
thirdState = digitalRead(thirdSensor);
fourthState = digitalRead(fourthSensor);
fifthState = digitalRead(fifthSensor);
sixthState = digitalRead(sixthSensor);
seventhState = digitalRead(seventhSensor);
eighthState = digitalRead(eighthSensor);
if((firstState != tab[0]) || (secondState != tab[1]) || (thirdState != tab[2]) || (fourthState != tab[3]) || (fifthState != tab[4]) || (sixthState != tab[5]) || (seventhState != tab[6]) || (eighthState != tab[7])){
tab[0]=firstState;
tab[1]=secondState;
tab[2]=thirdState;
tab[3]=fourthState;
tab[4]=fifthState;
tab[5]=sixthState;
tab[6]=seventhState;
tab[7]=eighthState;
if(firstState==1)
{
envoi=envoi+1;
}
if(secondState==1)
{
envoi=envoi+10;
}
if(thirdState==1)
{
envoi=envoi+100;
}
if(fourthState==1)
{
envoi=envoi+1000;
}
if(fifthState==1)
{
envoi=envoi+10000;
}
if(sixthState==1)
{
envoi=envoi+100000;
}
if(seventhState==1)
{
envoi=envoi+1000000;
}
if(eighthState==1)
{
envoi=envoi+10000000;
}
Serial1.print((char)envoi);
Serial.print(envoi);
}
}