Skip to content

Commit 86cb8b8

Browse files
committed
Made the shamash a regular candle; updated flickering logic to be more natural.
1 parent e8fa6eb commit 86cb8b8

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

hanukiah/hanukiah.ino

+24-19
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
const int shamash = 2; // output pin
2-
const int candles[] = {3, 4, 5, 6, 7, 8, 9, 10};
1+
const int candles[] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
32
const int button = 11; // input pin
43

54
int night = 0;
65

76
void setup() {
7+
Serial.begin(9600);
8+
9+
Serial.println("Hello hanukiah");
10+
811
// set up all outputs
9-
pinMode(shamash, OUTPUT);
10-
for (int i = 0; i < 8; ++i) {
12+
for (int i = 0; i < 9; ++i) {
1113
pinMode(candles[i], OUTPUT);
1214
}
1315
// set up input
1416
pinMode(button, INPUT);
17+
randomSeed(analogRead(12));
1518
}
1619

1720
unsigned long started = 0L;
1821
#define ONE_HOUR_MILLIS 3600000L
1922

2023
void loop() {
2124
// if switch down (with debounce)
22-
if (digitalRead(button) == HIGH) {
23-
night = (night + 1) % 9; // yes 9, so that it maxes at 8
24-
25-
if (night == 0) {
26-
digitalWrite(shamash, LOW);
27-
} else {
28-
digitalWrite(shamash, HIGH);
25+
if (digitalRead(button) == LOW) {
26+
Serial.println("button is pushed");
27+
night = (night + 1) % 9;
28+
if (night == 1) {
29+
night = 2;
2930
}
31+
Serial.print("night is now "); Serial.println(night);
3032

3133
// Are there better ways to do this? Yes. Do I care? No.
3234
// Turn on the the appropriate # of candles.
@@ -46,19 +48,22 @@ void loop() {
4648
} else if (millis() - started > ONE_HOUR_MILLIS) {
4749
// Candles go out after an hour
4850
night = 0;
49-
digitalWrite(shamash, LOW);
50-
for (int i = 0; i < 8; ++i) {
51+
for (int i = 0; i < 9; ++i) {
5152
digitalWrite(candles[i], LOW);
5253
}
5354
} else if (night > 0) {
5455
// Fake-flicker a candle
55-
int candle = random(night);
56-
int iters = random(5);
56+
int iters = random(4);
5757
for (int i = 0; i < iters; ++i) {
58-
digitalWrite(candles[candle], LOW);
59-
int offness = random(100);
60-
delay(offness);
61-
digitalWrite(candles[candle], HIGH);
58+
long candle = random(4000);
59+
if (candle < night) {
60+
digitalWrite(candles[candle], LOW);
61+
int offness = random(50);
62+
delay(offness);
63+
digitalWrite(candles[candle], HIGH);
64+
int onness = random(300);
65+
delay(onness);
66+
}
6267
}
6368
}
6469
}

0 commit comments

Comments
 (0)