質問編集履歴
2
修正しました.あとは13pinがうまく作動しないです…
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
arduinoを使用しnapion10m用のセンサと5m用のセンサと7m用のセンサの反応時間の変化からヒトの歩行速度を求めるプログラムを書いていますが
|
1
|
+
arduinoを使用しnapion10m用のセンサと5m用のセンサと7m用のセンサの反応時間の変化からヒトの歩行速度を求めるプログラムを書いていますがブザーが鳴っていない状況です。もし改善点などが分かる方がいましたらアドバイスください。よろしくお願いします。
|
2
2
|
|
3
3
|
|
4
4
|
|
1
修正しました.あとは13pinがうまく作動しないです…
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,29 +4,27 @@
|
|
4
4
|
|
5
5
|
```arduino
|
6
6
|
|
7
|
-
#include
|
7
|
+
#include <fastio.h>
|
8
|
-
|
8
|
+
|
9
|
-
#include
|
9
|
+
#include <MsTimer2.h>
|
10
|
-
|
10
|
+
|
11
|
-
|
11
|
+
fastIoPin<3>PPR1;
|
12
|
-
|
13
|
-
|
12
|
+
|
14
|
-
|
15
|
-
const int PPR3 = 5; //センサpin番号
|
16
|
-
|
17
|
-
const int PPR4 = 6; //センサpin番号
|
18
|
-
|
19
|
-
const int PPR5 = 7; //センサpin番号
|
20
|
-
|
21
|
-
|
13
|
+
fastIoPin<4>PPR2;
|
14
|
+
|
22
|
-
|
15
|
+
fastIoPin<5>PPR3;
|
16
|
+
|
17
|
+
fastIoPin<6>PPR4;
|
18
|
+
|
19
|
+
fastIoPin<7>PPR5;
|
20
|
+
|
21
|
+
fastIoPin<10>LED_BLUE;
|
22
|
+
|
23
|
+
fastIoPin<11>LED_GREEN;
|
24
|
+
|
23
|
-
|
25
|
+
fastIoPin<12>LED_RED;
|
24
|
-
|
25
|
-
|
26
|
+
|
26
|
-
|
27
|
-
const int LED_BLUE = 10; //青
|
28
|
-
|
29
|
-
f
|
27
|
+
#define buza 13
|
30
28
|
|
31
29
|
unsigned int state1 = 0;
|
32
30
|
|
@@ -58,7 +56,7 @@
|
|
58
56
|
|
59
57
|
unsigned long risingEdgeTime3 = 0;
|
60
58
|
|
61
|
-
unsigned long risingEdgeTime4 = 0;
|
59
|
+
unsigned long risingEdgeTime4 = 0;
|
62
60
|
|
63
61
|
unsigned long risingEdgeTime5 = 0;
|
64
62
|
|
@@ -76,11 +74,25 @@
|
|
76
74
|
|
77
75
|
void setup() {
|
78
76
|
|
79
|
-
MsTimer2::set(10
|
77
|
+
MsTimer2::set(10, value_count);//10ミリ秒ごとにtime_count関数を呼出
|
78
|
+
|
80
|
-
|
79
|
+
PPR1.pinMode(INPUT);
|
80
|
+
|
81
|
+
PPR2.pinMode(INPUT);
|
82
|
+
|
83
|
+
PPR3.pinMode(INPUT);
|
84
|
+
|
85
|
+
PPR4.pinMode(INPUT);
|
86
|
+
|
87
|
+
PPR5.pinMode(INPUT);
|
88
|
+
|
81
|
-
D
|
89
|
+
LED_BLUE.pinMode(OUTPUT);
|
82
|
-
|
90
|
+
|
83
|
-
D
|
91
|
+
LED_GREEN.pinMode(OUTPUT);
|
92
|
+
|
93
|
+
LED_RED.pinMode(OUTPUT);
|
94
|
+
|
95
|
+
pinMode(buza,OUTPUT);
|
84
96
|
|
85
97
|
Serial.begin(9600);
|
86
98
|
|
@@ -98,19 +110,19 @@
|
|
98
110
|
|
99
111
|
void value_count(void) {
|
100
112
|
|
101
|
-
|
113
|
+
state1 = digitalNoiselessRead1(3, 10, 3000); //PPR1 ピンが 0.01秒間 HIGH になっていたら,その後 3秒間 HIGH が返る
|
102
|
-
|
114
|
+
|
103
|
-
|
115
|
+
state2 = digitalNoiselessRead2(4, 10, 3000); //PPR2 ピンが 0.01秒間 HIGH になっていたら,その後 3秒間 HIGH が返る
|
104
|
-
|
116
|
+
|
105
|
-
|
117
|
+
state3 = digitalNoiselessRead3(5, 20, 3000); //PPR3 ピンが 0.02秒間 HIGH になっていたら,その後 3秒間 HIGH が返る
|
106
|
-
|
118
|
+
|
107
|
-
|
119
|
+
state4 = digitalNoiselessRead4(6, 20, 3000); //PPR4 ピンが 0.02秒間 HIGH になっていたら,その後 3秒間 HIGH が返る
|
108
|
-
|
120
|
+
|
109
|
-
|
121
|
+
state5 = digitalNoiselessRead5(7, 20, 3000); //PPR5 ピンが 0.1秒間 HIGH になっていたら,その後 3秒間 HIGH が返る
|
110
122
|
|
111
123
|
float t = (millis() - 30000) * 0.001; //loop開始からの経過秒
|
112
124
|
|
113
|
-
Serial.print(t,
|
125
|
+
Serial.print(t, 2);
|
114
126
|
|
115
127
|
Serial.print(" ");
|
116
128
|
|
@@ -136,15 +148,9 @@
|
|
136
148
|
|
137
149
|
|
138
150
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
151
|
unsigned int digitalNoiselessRead1(unsigned int pin1, long monitoringPeriod1, long highPeriod1) {
|
146
152
|
|
147
|
-
state1 = digitalRead
|
153
|
+
state1 = PPR1.digitalRead();
|
148
154
|
|
149
155
|
unsigned long now = millis();
|
150
156
|
|
@@ -158,8 +164,6 @@
|
|
158
164
|
|
159
165
|
lastState1 = state1;
|
160
166
|
|
161
|
-
|
162
|
-
|
163
167
|
if (stage1 == 1) { //監視期間中
|
164
168
|
|
165
169
|
if (state1 == LOW) { //ノイズだった
|
@@ -198,7 +202,7 @@
|
|
198
202
|
|
199
203
|
unsigned int digitalNoiselessRead2(unsigned int pin2, long monitoringPeriod2, long highPeriod2) {
|
200
204
|
|
201
|
-
state2 = digitalRead
|
205
|
+
state2 = PPR2.digitalRead();
|
202
206
|
|
203
207
|
unsigned long now = millis();
|
204
208
|
|
@@ -250,44 +254,230 @@
|
|
250
254
|
|
251
255
|
|
252
256
|
|
257
|
+
unsigned int digitalNoiselessRead3(unsigned int pin3, long monitoringPeriod3, long highPeriod3) {
|
258
|
+
|
259
|
+
state3 = PPR3.digitalRead();
|
260
|
+
|
261
|
+
unsigned long now = millis();
|
262
|
+
|
263
|
+
if (stage3 == 0 && lastState3 == LOW && state3 == HIGH) { //立ち上がり検出
|
264
|
+
|
265
|
+
risingEdgeTime3 = now;
|
266
|
+
|
253
|
-
//
|
267
|
+
stage3 = 1; //監視期間開始
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
lastState3 = state3;
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
if (stage3 == 1) { //監視期間中
|
276
|
+
|
277
|
+
if (state3 == LOW) { //ノイズだった
|
278
|
+
|
279
|
+
stage3 = 0;
|
280
|
+
|
281
|
+
} else if (now - risingEdgeTime3 >= monitoringPeriod3) {
|
282
|
+
|
283
|
+
stage3 = 2; //HIGH 期間へ移行
|
284
|
+
|
285
|
+
} else {
|
286
|
+
|
287
|
+
state3 = LOW; //監視期間中は LOW
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
} else if (stage3 == 2) { //HIGH期間中
|
292
|
+
|
293
|
+
if (now - risingEdgeTime3 <= monitoringPeriod3 + highPeriod3) {
|
294
|
+
|
295
|
+
state3 = HIGH; //HIGH期間中は HIGH
|
296
|
+
|
297
|
+
} else {
|
298
|
+
|
299
|
+
stage3 = 0; //HIGH期間終了
|
300
|
+
|
301
|
+
}
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
return state3;
|
306
|
+
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
unsigned int digitalNoiselessRead4(unsigned int pin4, long monitoringPeriod4, long highPeriod4) {
|
312
|
+
|
313
|
+
state4 = PPR4.digitalRead();
|
314
|
+
|
315
|
+
unsigned long now = millis();
|
316
|
+
|
317
|
+
if (stage4 == 0 && lastState4 == LOW && state4 == HIGH) { //立ち上がり検出
|
318
|
+
|
319
|
+
risingEdgeTime4 = now;
|
320
|
+
|
321
|
+
stage4 = 1; //監視期間開始
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
lastState4 = state4;
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
if (stage4 == 1) { //監視期間中
|
330
|
+
|
331
|
+
if (state4 == LOW) { //ノイズだった
|
332
|
+
|
333
|
+
stage4 = 0;
|
334
|
+
|
335
|
+
} else if (now - risingEdgeTime4 >= monitoringPeriod4) {
|
336
|
+
|
337
|
+
stage4 = 2; //HIGH 期間へ移行
|
338
|
+
|
339
|
+
} else {
|
340
|
+
|
341
|
+
state4 = LOW; //監視期間中は LOW
|
342
|
+
|
343
|
+
}
|
344
|
+
|
345
|
+
} else if (stage4 == 2) { //HIGH期間中
|
346
|
+
|
347
|
+
if (now - risingEdgeTime4 <= monitoringPeriod4 + highPeriod4) {
|
348
|
+
|
349
|
+
state4 = HIGH; //HIGH期間中は HIGH
|
350
|
+
|
351
|
+
} else {
|
352
|
+
|
353
|
+
stage4 = 0; //HIGH期間終了
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
return state4;
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
unsigned int digitalNoiselessRead5(unsigned int pin5, long monitoringPeriod5, long highPeriod5) {
|
366
|
+
|
367
|
+
state5 = PPR5.digitalRead();
|
368
|
+
|
369
|
+
unsigned long now = millis();
|
370
|
+
|
371
|
+
if (stage5 == 0 && lastState5 == LOW && state5 == HIGH) { //立ち上がり検出
|
372
|
+
|
373
|
+
risingEdgeTime5 = now;
|
374
|
+
|
375
|
+
stage5 = 1; //監視期間開始
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
lastState5 = state5;
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
if (stage5 == 1) { //監視期間中
|
384
|
+
|
385
|
+
if (state5 == LOW) { //ノイズだった
|
386
|
+
|
387
|
+
stage5 = 0;
|
388
|
+
|
389
|
+
} else if (now - risingEdgeTime5 >= monitoringPeriod5) {
|
390
|
+
|
391
|
+
stage5 = 2; //HIGH 期間へ移行
|
392
|
+
|
393
|
+
} else {
|
394
|
+
|
395
|
+
state5 = LOW; //監視期間中は LOW
|
396
|
+
|
397
|
+
}
|
398
|
+
|
399
|
+
} else if (stage5 == 2) { //HIGH期間中
|
400
|
+
|
401
|
+
if (now - risingEdgeTime5 <= monitoringPeriod5 + highPeriod5) {
|
402
|
+
|
403
|
+
state5 = HIGH; //HIGH期間中は HIGH
|
404
|
+
|
405
|
+
} else {
|
406
|
+
|
407
|
+
stage5 = 0; //HIGH期間終了
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
}
|
412
|
+
|
413
|
+
return state5;
|
414
|
+
|
415
|
+
}
|
254
416
|
|
255
417
|
|
256
418
|
|
257
419
|
void loop() {
|
258
420
|
|
259
|
-
while (1) {
|
260
|
-
|
261
|
-
//LED//
|
262
|
-
|
263
|
-
if (state1 == LOW && state2 == LOW && state3 == LOW && state4 == LOW && state5 == LOW) {
|
421
|
+
if (state1 == LOW && state2 == LOW && state3 == LOW && state4 == LOW && state5 == LOW) { //青 00000
|
264
|
-
|
265
|
-
|
422
|
+
|
266
|
-
|
267
|
-
digitalWrite
|
423
|
+
LED_RED.digitalWrite(LOW);
|
268
|
-
|
424
|
+
|
269
|
-
digitalWrite
|
425
|
+
LED_GREEN.digitalWrite(HIGH);
|
270
|
-
|
426
|
+
|
271
|
-
digitalWrite
|
427
|
+
LED_BLUE.digitalWrite(LOW); //青
|
272
|
-
|
428
|
+
|
273
|
-
}
|
429
|
+
}
|
274
|
-
|
430
|
+
|
275
|
-
else if (state1 == HIGH && state2 == HIGH && state3 == LOW && state4 == LOW && state5 == LOW) {//5m~10m黄色
|
431
|
+
else if (state1 == HIGH && state2 == HIGH && state3 == LOW && state4 == LOW && state5 == LOW) {//5m~10m黄色11000
|
276
|
-
|
277
|
-
|
432
|
+
|
278
|
-
|
279
|
-
digitalWrite
|
433
|
+
LED_RED.digitalWrite(HIGH);
|
280
|
-
|
434
|
+
|
281
|
-
digitalWrite
|
435
|
+
LED_GREEN.digitalWrite(LOW);
|
282
|
-
|
436
|
+
|
283
|
-
digitalWrite
|
437
|
+
LED_BLUE.digitalWrite(HIGH); //黄
|
284
|
-
|
438
|
+
|
285
|
-
}
|
439
|
+
}
|
440
|
+
|
286
|
-
|
441
|
+
else if (state1 == HIGH && state2 == LOW && state3 == LOW && state4 == LOW && state5 == LOW) {//5m~10m黄色 10000
|
442
|
+
|
443
|
+
LED_RED.digitalWrite(HIGH);
|
444
|
+
|
287
|
-
|
445
|
+
LED_GREEN.digitalWrite(LOW);
|
446
|
+
|
288
|
-
|
447
|
+
LED_BLUE.digitalWrite(HIGH); //黄
|
448
|
+
|
289
|
-
}
|
449
|
+
}
|
450
|
+
|
290
|
-
|
451
|
+
else if (state1 == LOW && state2 == HIGH && state3 == LOW && state4 == LOW && state5 == LOW) {//5m~10m黄色 01000
|
452
|
+
|
453
|
+
LED_RED.digitalWrite(HIGH);
|
454
|
+
|
455
|
+
LED_GREEN.digitalWrite(LOW);
|
456
|
+
|
457
|
+
LED_BLUE.digitalWrite(HIGH); //黄
|
458
|
+
|
291
|
-
}
|
459
|
+
}
|
460
|
+
|
461
|
+
else if (state1 == HIGH && state2 == HIGH && state3 == HIGH && state4 == HIGH && state5 == LOW) {//5m以内赤 11110
|
462
|
+
|
463
|
+
digitalWrite<13>(HIGH);
|
464
|
+
|
465
|
+
LED_RED.digitalWrite(HIGH);
|
466
|
+
|
467
|
+
LED_GREEN.digitalWrite(HIGH);
|
468
|
+
|
469
|
+
LED_BLUE.digitalWrite(HIGH); //赤
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
//その他点灯方法記載の省略
|
474
|
+
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
|
292
482
|
|
293
483
|
```
|