File tree 1 file changed +51
-8
lines changed 1 file changed +51
-8
lines changed Original file line number Diff line number Diff line change 1
- #define DEBUG
1
+ // #define DEBUG
2
2
#define ON_PIN 3
3
+ #define BT_PIN 5
3
4
#define IR_PIN A6
4
5
#define PR_PIN A4
5
6
#define IR_TRH 900
@@ -12,42 +13,84 @@ void setup() {
12
13
pinMode (ON_PIN, OUTPUT);
13
14
pinMode (IR_PIN, INPUT);
14
15
pinMode (PR_PIN, INPUT);
16
+ pinMode (BT_PIN, INPUT_PULLUP);
15
17
16
18
#ifdef DEBUG
17
19
Serial.begin (9600 );
18
20
#endif
19
21
}
20
22
23
+ bool trig = false ;
21
24
bool on = false ;
25
+ bool bt = false ;
22
26
int ir, pr;
23
27
unsigned long t = 0 ;
28
+ char _src = ' ?' ;
29
+
30
+ bool irTrig (int ir, int pr, bool on) {
31
+ if ((!on and ir < IR_TRH and pr < PR_TRH) or (on and ir < IR_TRH)) {
32
+ if (on) {
33
+ _src = ' ?' ;
34
+ } else {
35
+ _src = ' i' ;
36
+ }
37
+
38
+ return true ;
39
+ }
40
+
41
+ return false ;
42
+ }
43
+
44
+ bool btPush (bool bt, bool on) {
45
+ if (bt) {
46
+ if (on) {
47
+ _src = ' ?' ;
48
+ } else {
49
+ _src = ' b' ;
50
+ }
51
+
52
+ return true ;
53
+ }
54
+
55
+ return false ;
56
+ }
24
57
25
58
void loop () {
26
59
ir = analogRead (IR_PIN);
27
60
pr = analogRead (PR_PIN);
61
+ bt = digitalRead (BT_PIN) == LOW;
62
+
63
+ trig = (irTrig (ir, pr, on) or btPush (bt, on));
28
64
29
65
#ifdef DEBUG
30
66
Serial.print (" IR: " );
31
67
Serial.print (ir);
32
68
Serial.print (" / PR: " );
33
- Serial.println (pr);
69
+ Serial.print (pr);
70
+ Serial.print (" / BT: " );
71
+ Serial.print (bt);
72
+ Serial.print (" / SRC: " );
73
+ Serial.println (_src);
34
74
#endif
35
75
36
- if ((!on and ir < IR_TRH and pr < PR_TRH) or (on and ir < IR_TRH) ) {
76
+ if (trig ) {
37
77
on = !on;
38
78
39
79
digitalWrite (ON_PIN, on);
40
- delay (5 * graceMillis);
80
+ delay (5 * graceMillis);
41
81
42
82
if (on) {
43
83
t = millis ();
44
84
}
45
85
}
46
86
47
- if (on) {
48
- if (millis () - t > lightMillis) {
49
- digitalWrite (ON_PIN, !on);
50
- t = millis ();
87
+ if (_src == ' i' ) {
88
+ if (on) {
89
+ if (millis () - t > lightMillis) {
90
+ digitalWrite (ON_PIN, !on);
91
+ t = millis ();
92
+ _src = ' ?' ;
93
+ }
51
94
}
52
95
}
53
96
You can’t perform that action at this time.
0 commit comments