File tree 1 file changed +29
-8
lines changed 1 file changed +29
-8
lines changed Original file line number Diff line number Diff line change 1
- #define ONOFF_PIN 2
2
- #define IRSIG_PIN A0
3
- #define ONOFF_TRH 800
1
+ #define DEBUG
2
+ #define ONOFF_PIN 3
3
+ #define IRSIG_PIN A6
4
+ #define ONOFF_TRH 900
4
5
5
6
void setup () {
6
7
pinMode (ONOFF_PIN, OUTPUT);
7
8
pinMode (IRSIG_PIN, INPUT);
9
+
10
+ #ifdef DEBUG
11
+ Serial.begin (9600 );
12
+ #endif
8
13
}
9
14
15
+ bool on = false ;
10
16
int av;
17
+ unsigned long t = 0 ;
11
18
12
19
void loop () {
13
20
av = analogRead (IRSIG_PIN);
14
21
22
+ #ifdef DEBUG
23
+ Serial.println (av);
24
+ #endif
25
+
26
+ if (av < ONOFF_TRH) {
27
+ on = !on;
15
28
16
- if (av <= ONOFF_TRH) {
17
- digitalWrite (ONOFF_PIN, HIGH);
18
- } else {
19
- digitalWrite (ONOFF_PIN, LOW);
29
+ digitalWrite (ONOFF_PIN, on);
30
+ delay (500 );
31
+
32
+ if (on) {
33
+ t = millis ();
34
+ }
20
35
}
21
36
37
+ if (on) {
38
+ if (millis () - t > 30000 ) {
39
+ digitalWrite (ONOFF_PIN, !on);
40
+ t = millis ();
41
+ }
42
+ }
22
43
23
- delay (100 );
44
+ delay (50 );
24
45
}
You can’t perform that action at this time.
0 commit comments