-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathljusstake.cpp
122 lines (103 loc) · 2.63 KB
/
ljusstake.cpp
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
121
122
/*
* A program for handling the light show of the
* "ljusstake project".
*
* Author: Peter Jonsson <95jonpet.se>
* Version: 2015-12-02
*/
#include <Adafruit_NeoPixel.h>
#define DATA_PIN 6
#define NUM_LEDS 7
#define BRIGHTNESS 32
#define DELAY 20
// Initialize the led strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, DATA_PIN, NEO_GRB + NEO_KHZ800);
uint8_t red = 255;
uint8_t green = 255;
uint8_t blue = 255;
/*
* Set up everything and start the light show.
*/
void setup() {
randomSeed(analogRead(0)); // Random seed
strip.begin();
strip.show();
strip.setBrightness(BRIGHTNESS);
}
/*
* The looping function in which the light show
* takes place.
*/
void loop() {
//rainbow(DELAY);
//normal(10000);
//randomColor(10000);
uint8_t nextRed, nextGreen, nextBlue;
nextRed = random(256);
nextGreen = random(256);
nextBlue = random(256);
while (red != nextRed || green != nextGreen || blue != nextBlue) {
red += constrain(nextRed - red, -1, 1);
green += constrain(nextGreen - green, -1, 1);
blue += constrain(nextBlue - blue, -1, 1);
uint8_t i;
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
delay(DELAY);
}
delay(5000);
}
/*
* Displays a normal and quite boring white color
* for all LEDs.
*/
void normal(unsigned int duration) {
uint16_t i;
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 255, 255));
}
strip.show();
delay(duration);
}
void randomColor(unsigned int duration) {
uint8_t red, green, blue;
red = random(256);
blue = random(256);
green = random(256);
uint16_t i;
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(red, green, blue));
}
strip.show();
delay(duration);
}
/*
* Displays a rainbow.
*/
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
strip.show();
delay(wait);
}
}
/*
* Input a value 0 to 255 to get a color value.
* The colors are a transition r - g - b - back to r.
*/
uint32_t Wheel(byte WheelPos) {
if (WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}