forked from macetech/RGBShades
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRGBShades.ino
138 lines (106 loc) · 4.64 KB
/
RGBShades.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
121
122
123
124
125
126
127
128
129
130
131
132
133
// RGB Shades Demo Code
// Copyright (c) 2014 macetech LLC
// This software is provided under the MIT License (see license.txt)
// Special credit to Mark Kriegsman for XY mapping code
//
// Use Version 3.0 or later https://github.com/FastLED/FastLED
// ZIP file https://github.com/FastLED/FastLED/archive/master.zip
//
// Use Arduino IDE 1.0 or later
// Select device "Arduino Pro or Pro Mini (5V, 16MHz) w/ATmega328
//
// [Press] the SW1 button to cycle through available effects
// Effects will also automatically cycle at startup
// [Press and hold] the SW1 button (one second) to switch between auto and manual mode
// * Auto Mode (one blue blink): Effects automatically cycle over time
// * Manual Mode (two red blinks): Effects must be selected manually with SW1 button
//
// [Press] the SW2 button to cycle through available brightness levels
// [Press and hold] the SW2 button (one second) to reset brightness to startup value
// RGB Shades data output to LEDs is on pin 5
#define LED_PIN 5
// RGB Shades color order (Green/Red/Blue)
#define COLOR_ORDER GRB
#define CHIPSET WS2811
// Global maximum brightness value, maximum 255
#define MAXBRIGHTNESS 72
#define STARTBRIGHTNESS 127
byte currentBrightness = STARTBRIGHTNESS; // 0-255 will be scaled to 0-MAXBRIGHTNESS
// Include FastLED library and other useful files
#include <FastLED.h>
#include "XYmap.h"
#include "utils.h"
#include "effects.h"
#include "buttons.h"
// Runs one time at the start of the program (power up or reset)
void setup() {
// write FastLED configuration data
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, LAST_VISIBLE_LED + 1);//.setCorrection(TypicalSMD5050);
// set global brightness value
FastLED.setBrightness( scale8(STARTBRIGHTNESS, MAXBRIGHTNESS) );
// configure input buttons
pinMode(MODEBUTTON, INPUT_PULLUP);
pinMode(BRIGHTNESSBUTTON, INPUT_PULLUP);
}
// list of functions that will be displayed
functionList effectList[] = {threeSine,
threeDee,
plasma,
confetti,
rider,
glitter,
slantBars,
colorFill,
sideRain };
// Timing parameters
#define cycleTime 15000
#define hueTime 30
// Runs over and over until power off or reset
void loop()
{
currentMillis = millis(); // save the current timer value
updateButtons(); // read, debounce, and process the buttons
// Check the mode button (for switching between effects)
switch(buttonStatus(0)) {
case BTNRELEASED: // button was pressed and released quickly
cycleMillis = currentMillis;
if (++currentEffect >= numEffects) currentEffect = 0; // loop to start of effect list
effectInit = false; // trigger effect initialization when new effect is selected
break;
case BTNLONGPRESS: // button was held down for a while
autoCycle = !autoCycle; // toggle auto cycle mode
confirmBlink(); // one blue blink: auto mode. two red blinks: manual mode.
break;
}
// Check the brightness adjust button
switch(buttonStatus(1)) {
case BTNRELEASED: // button was pressed and released quickly
currentBrightness += 16; // increase the brightness (wraps to lowest)
FastLED.setBrightness(scale8(currentBrightness,MAXBRIGHTNESS));
break;
case BTNLONGPRESS: // button was held down for a while
currentBrightness = STARTBRIGHTNESS; // reset brightness to startup value
FastLED.setBrightness(scale8(currentBrightness,MAXBRIGHTNESS));
break;
}
// switch to a new effect every cycleTime milliseconds
if (currentMillis - cycleMillis > cycleTime && autoCycle == true) {
cycleMillis = currentMillis;
if (++currentEffect >= numEffects) currentEffect = 0; // loop to start of effect list
effectInit = false; // trigger effect initialization when new effect is selected
}
// increment the global hue value every hueTime milliseconds
if (currentMillis - hueMillis > hueTime) {
hueMillis = currentMillis;
hueCycle(1); // increment the global hue value
}
// run the currently selected effect every effectDelay milliseconds
if (currentMillis - effectMillis > effectDelay) {
effectMillis = currentMillis;
effectList[currentEffect](); // run the selected effect function
random16_add_entropy(1); // make the random values a bit more random-ish
}
// run a fade effect too if the confetti effect is running
if (effectList[currentEffect] == confetti) fadeAll(1);
FastLED.show(); // send the contents of the led memory to the LEDs
}