Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int NUM_CANDLES = 9;
- int candles[] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; // Define the pins for each candle. First is shamash
- int btn = 10; // Define the pin for the button
- int ner = 0;
- // the setup routine runs once when you press reset:
- void setup() {
- // initialize each candle pin to OUTPUT
- for (int i = 0; i < NUM_CANDLES; i++) {
- pinMode(candles[i], OUTPUT);
- }
- // initialize the button pin to INPUT with the built in pullup resistor
- pinMode(btn, INPUT_PULLUP);
- }
- // the loop routine runs over and over again forever:
- void loop() {
- if (digitalRead(btn) == HIGH) {
- // Button is not pressed
- } else {
- // Button was pressed!
- ner++;
- ner %= 8;
- }
- for (int i = 0; i < NUM_CANDLES; i++) {
- if (i >= ner) {
- digitalWrite(candles[i], HIGH); // Turn the candle on
- } else {
- digitalWrite(candles[i], LOW); // Turn the candle off
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement