forked from iliketomakestuff/adventcalendartree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadventTree.ino
121 lines (95 loc) · 3.39 KB
/
adventTree.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Advent Calendar Christmas Tree project
// http://www.iliketomakestuff.com/make-arduino-powered-advent-calendar
// By: Bob Clagett for I Like To Make Stuff
//modified from example code from Adafruit.
//https://github.com/adafruit/Adafruit-WS2801-Library
/*
This code is messy, and unsupported :)
I was in a hurry. Feel free to improve it and send pull requests!
*/
#include "Adafruit_WS2801.h"
#include "SPI.h" // Comment out this line if using Trinket or Gemma
#ifdef __AVR_ATtiny85__
#include <avr/power.h>
#endif
uint8_t dataPin = 4; // Yellow wire on Adafruit Pixels
uint8_t clockPin = 5; // Green wire on Adafruit Pixels
int BUTTON_PIN=3;
long randNumber;
int val=0;
int dayCounter=0;
int i=0;
bool causeDelay=false;
int baseBrightness = 10;
int maxBrightnessChange = 5;
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are unsigned long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
// Don't forget to connect the ground wire to Arduino ground,
// and the +5V wire to a +5V supply
Adafruit_WS2801 strip = Adafruit_WS2801(25, dataPin, clockPin);
void setup() {
randomSeed(analogRead(0));
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000L)
clock_prescale_set(clock_div_1); // Enable 16 MHz on Trinket
#endif
pinMode(BUTTON_PIN, INPUT);
strip.begin();
// Update LED contents, to start they are all 'off'
strip.show();
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(BUTTON_PIN);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
// if the button state has changed:
if (reading != buttonState) {
buttonState = reading;
// only toggle the LED if the new button state is HIGH
if (buttonState == HIGH) {
dayCounter++;
ledState = !ledState;
}
}
}
// set the LED:
// if (buttonState == HIGH) { // check if the input is HIGH (button released)
if (dayCounter>25){
dayCounter=0;
}
setupColoredDays();
// }
lastButtonState = reading;
}
void setupColoredDays(){
for (i=0; i < 25; i++) {
if(i<dayCounter){
int clr0 = baseBrightness - random(maxBrightnessChange);
int clr1 = baseBrightness - random(maxBrightnessChange);
int clr2 = baseBrightness - random(maxBrightnessChange);
strip.setPixelColor(i, clr0,clr1,clr2);
if(i==24){
strip.setPixelColor(i, 255,255,255);
}
}else{
strip.setPixelColor(i, 0,0,0);
}
}
strip.show(); // write all the pixels out
delay(150);
}