8b38af38
sblas
Ajout du programm...
|
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
#include <SoftwareSerial.h>
SoftwareSerial soft1(A3,A2);
SoftwareSerial soft2(6,5);
SoftwareSerial soft3(9,10);
const int in1 = A5;
const int out1 = A4;
const int in2 = 8;
const int out2 = 7;
const int in3 = 11;
const int out3 = 12;
const int in4 = 2;
const int out4 = 3;
int prem = 0;
int papa = 0;
int potar = A0;
void setup()
{
Serial.begin(9600);
soft1.begin(9600);
soft2.begin(9600);
soft3.begin(9600);
pinMode(in1,INPUT);
pinMode(out1,OUTPUT);
pinMode(in2,INPUT);
pinMode(out2,OUTPUT);
pinMode(in3,INPUT);
pinMode(out3,OUTPUT);
pinMode(in4,INPUT);
pinMode(out4,OUTPUT);
digitalWrite(out1,LOW);
digitalWrite(out2,LOW);
digitalWrite(out3,LOW);
digitalWrite(out4,LOW);
}
void loop()
{
String msg="";
char inByte='a';
int tps;
int timeout;
int fin1=0,fin2=0,fin3=0,fin4=0;
char id = 0b01100001;
if(digitalRead(in1)==HIGH){
digitalWrite(out1,HIGH);
soft1.listen();
timeout=0;
tps=millis();
while(soft1.available()<=0 && timeout<1000){
timeout= millis() - tps;
}
if(timeout<1000){
fin1=1;
while(inByte != '\n'){
inByte = soft1.read();
if(inByte !='\n'){
msg += inByte;
delay(10);
}
}
if(prem==0){
prem=1;
papa=1;
msg += id;
if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
else if((id & 0xF0) ==0x40) msg += 0b00000100;
msg += '\n';
}
else msg+= '\n';
}
digitalWrite(out1, LOW);
delay(50);
}
else if(digitalRead(in2)==HIGH){
digitalWrite(out2,HIGH);
soft2.listen();
timeout=0;
tps=millis();
while(soft2.available()<=0 && timeout<1000){
timeout= millis() - tps;
}
if(timeout<1000){
fin2=1;
while(inByte != '\n'){
inByte = soft2.read();
if(inByte !='\n'){
msg += inByte;
delay(10);
}
}
if(prem==0){
prem=1;
papa=2;
msg += id;
if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
else if((id & 0xF0) ==0x40) msg += 0b00000100;
msg += '\n';
}
else msg+= '\n';
}
digitalWrite(out2, LOW);
delay(50);
}
else if(digitalRead(in3)==HIGH){
digitalWrite(out3,HIGH);
soft3.listen();
timeout=0;
tps=millis();
while(soft3.available()<=0 && timeout<1000){
timeout= millis() - tps;
}
if(timeout<1000){
fin3=1;
while(inByte != '\n'){
inByte = soft3.read();
if(inByte !='\n'){
msg += inByte;
delay(10);
}
}
if(prem==0){
prem=1;
papa=3;
msg += id;
if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
else if((id & 0xF0) ==0x40) msg += 0b00000100;
msg += '\n';
}
else msg+= '\n';
}
digitalWrite(out3, LOW);
delay(50);
}
else if(digitalRead(in4)==HIGH){
digitalWrite(out4,HIGH);
timeout=0;
tps=millis();
while(Serial.available()<=0 && timeout<1000){
timeout= millis() - tps;
}
if(timeout<1000){
fin4=1;
while(inByte != '\n'){
inByte = Serial.read();
if(inByte !='\n'){
msg += inByte;
delay(10);
}
}
if(prem==0){
prem=1;
papa=4;
msg += id;
if((id & 0xF0) ==0x60) msg += '{'; //char pour 123
else if((id & 0xF0) ==0x40) msg += 0b00000100;
msg += '\n';
}
else msg+= '\n';
}
digitalWrite(out4, LOW);
delay(50);
}
if(fin1==1 || fin2==1 || fin3==1 || fin4==1){
if((fin1==1 && papa == 1) || (fin1 == 0)){
timeout=0;
tps = millis();
while(timeout<1000){
digitalWrite(out1,HIGH);
timeout= millis() - tps;
if(fin1==1) timeout=0;
if(digitalRead(in1)==HIGH){
soft1.print(msg);
soft1.flush();
timeout = 1001;
}
}
digitalWrite(out1,LOW);
}
if((fin2==1 && papa == 2) || (fin2 == 0)){
timeout=0;
tps = millis();
while(timeout<1000){
digitalWrite(out2,HIGH);
timeout= millis() - tps;
if(fin2==1) timeout=0;
if(digitalRead(in2)==HIGH){
soft2.print(msg);
soft2.flush();
digitalWrite(out2,LOW);
timeout = 1001;
}
}
digitalWrite(out2,LOW);
}
if((fin3==1 && papa == 3) || (fin3 == 0)){
timeout=0;
tps = millis();
while(timeout<1000){
digitalWrite(out3,HIGH);
timeout= millis() - tps;
if(fin3==1) timeout=0;
if(digitalRead(in3)==HIGH){
soft3.print(msg);
soft3.flush();
digitalWrite(out3,LOW);
timeout = 1001;
}
}
digitalWrite(out3,LOW);
}
if((fin4==1 && papa == 4) || (fin4 == 0)){
timeout=0;
tps = millis();
while(timeout<1000){
digitalWrite(out4,HIGH);
timeout= millis() - tps;
if(fin4==1) timeout=0;
if(digitalRead(in4)==HIGH){
Serial.print(msg);
Serial.flush();
digitalWrite(out4,LOW);
timeout = 1001;
}
}
digitalWrite(out4,LOW);
}
}
}
|