Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. int NUM_CANDLES = 9;
  2. int candles[] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; // Define the pins for each candle. First is shamash
  3. int btn = 10; // Define the pin for the button
  4.  
  5. int ner = 0;
  6.  
  7. // the setup routine runs once when you press reset:
  8. void setup() {                
  9.   // initialize each candle pin to OUTPUT
  10.   for (int i = 0; i < NUM_CANDLES; i++) {
  11.     pinMode(candles[i], OUTPUT);  
  12.   }
  13.  
  14.   // initialize the button pin to INPUT with the built in pullup resistor
  15.   pinMode(btn, INPUT_PULLUP);
  16. }
  17.  
  18. // the loop routine runs over and over again forever:
  19. void loop() {
  20.  
  21.   if (digitalRead(btn) == HIGH) {
  22.     // Button is not pressed
  23.   } else {
  24.     // Button was pressed!
  25.     ner++;
  26.     ner %= 8;
  27.   }
  28.  
  29.   for (int i = 0; i < NUM_CANDLES; i++) {
  30.     if (i >= ner) {
  31.       digitalWrite(candles[i], HIGH); // Turn the candle on
  32.     } else {
  33.       digitalWrite(candles[i], LOW); // Turn the candle off
  34.     }
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement