Skip to content

Commit 8184418

Browse files
committed
feat(hexalamp): polish the algorithm
1 parent 09ece10 commit 8184418

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

hexalamp/hexalamp.ino

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
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
45

56
void setup() {
67
pinMode(ONOFF_PIN, OUTPUT);
78
pinMode(IRSIG_PIN, INPUT);
9+
10+
#ifdef DEBUG
11+
Serial.begin(9600);
12+
#endif
813
}
914

15+
bool on = false;
1016
int av;
17+
unsigned long t = 0;
1118

1219
void loop() {
1320
av = analogRead(IRSIG_PIN);
1421

22+
#ifdef DEBUG
23+
Serial.println(av);
24+
#endif
25+
26+
if (av < ONOFF_TRH) {
27+
on = !on;
1528

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+
}
2035
}
2136

37+
if (on) {
38+
if (millis() - t > 30000) {
39+
digitalWrite(ONOFF_PIN, !on);
40+
t = millis();
41+
}
42+
}
2243

23-
delay(100);
44+
delay(50);
2445
}

0 commit comments

Comments
 (0)