1unsigned long pulse_width;
2
3int ledPin1 = 2;
4int ledPin2 = 3;
5int ledPin3 = 4;
6int ledPin4 = 5;
7int ledPin5 = 6;
8
9
18
19int triggerPin = 7;
20int monitorPin = 8;
21
22
23void setup() {
24
25 delay(250);
26 Serial.begin(9600);
27 Serial1.begin(9600);
28 Serial2.begin(9600);
29 Serial3.begin(9600);
30
31 delay(250);
32
33
42
43 pinMode(ledPin1,OUTPUT);
44
45 pinMode(triggerPin, OUTPUT);
46 pinMode(monitorPin, INPUT);
47 digitalWrite(triggerPin, LOW);
48
49
50 digitalWrite(ledPin1,LOW);
51
52
53
54}
55
56String id1 = "";
57String id2 = "";
58String id3 = "";
59
60String old_id1 = "";
61String very_old_id1 = "";
62String old_id2 = "";
63String very_old_id2 = "";
64String old_id3 = "";
65String very_old_id3 = "";
66
67void touchDown() {
68
69
74}
75
76
77void pickUp() {
78
79
84
85}
86
87
88void loop() {
89
90
91pulse_width = pulseIn(monitorPin, HIGH);
92 if(pulse_width != 0){
93 pulse_width = pulse_width/10;
94 String s;
95 Serial.println("#DIST:"+String(pulse_width) + ";");
96 }
97
98
99
100
101 delay(200);
102
103
104 very_old_id1 = old_id1;
105 old_id1 = id1;
106 id1 = "";
107
108
109
110
111 while (Serial1.available() > 0) {
112 byte inByte = (byte)Serial1.read();
113 id1 = id1 + inByte;
114 }
115 if (id1.length() > 8) {
116 Serial.flush();
117
118 if ((very_old_id1 == "") && (old_id1 == "")) {
119 Serial.println("#RFID1:"+id1+" PUT;");
120 touchDown();
121 }
122
123 }
124
125 if ((very_old_id1.length() > 8) && (old_id1 == "") && (id1 == "")) {
126 Serial.println("#RFID1:"+very_old_id1+" TKN;");
127 pickUp();
128 }
129
130
131 very_old_id2 = old_id2;
132 old_id2 = id2;
133 id2 = "";
134
135
136
137 while (Serial2.available() > 0) {
138 byte inByte = (byte)Serial2.read();
139 id2 = id2 + inByte;
140 }
141 if (id2.length() > 8) {
142 Serial.flush();
143
144 if ((very_old_id2 == "") && (old_id2 == "")) {
145 Serial.println("#RFID2:"+id2+" PUT;");
146 touchDown();
147 }
148
149 }
150
151 if ((very_old_id2.length() > 8) && (old_id2 == "") && (id2 == "")) {
152 Serial.println("#RFID2:"+very_old_id2+" TKN;");
153 pickUp();
154 }
155
156
157 very_old_id3 = old_id3;
158 old_id3 = id3;
159 id3 = "";
160
161
162
163 while (Serial3.available() > 0) {
164 byte inByte = (byte)Serial3.read();
165 id3 = id3 + inByte;
166 }
167 if (id3.length() > 8) {
168 Serial.flush();
169
170 if ((very_old_id3 == "") && (old_id3 == "")) {
171 Serial.println("#RFID3:"+id3+" PUT;");
172 touchDown();
173 }
174
175 }
176
177 if ((very_old_id3.length() > 8) && (old_id3 == "") && (id3 == "")) {
178 Serial.println("#RFID3:"+very_old_id3+" TKN;");
179 pickUp();
180 }
181
182
183
184if (millis() > 10000) {
185
186}
187
188
189}
190
191
cuppermo
a year ago
I don't Get it, This is Very Cool But Confusing?!😕