-
Notifications
You must be signed in to change notification settings - Fork 46
/
RGBShades.ino
147 lines (116 loc) · 5.03 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
134
135
136
137
138
139
140
141
142
// RGB Shades Demo Code
// Copyright (c) 2015 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
//
// If your RGB Shades were purchased before July 2015:
// This version has the standard Arduino bootloader. R9 and R10 near the control buttons will be present.
// Select the “Arduino Pro or Pro Mini” option.
// Then, go back into the Tools menu and find the Processor option and select “ATmega328 (5V, 16MHz)”.
//
// If your RGB Shades were purchased after July 2015:
// This version has the Optiboot bootloader. R9 and 10 near the control buttons will be missing.
// Select the “Arduino Mini” option.
// Then, go back into the Tools menu and find the Processor option and select “ATmega328”.
//
// [Press] the SW1 button to cycle through available effects
// [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
//
// Brightness, selected effect, and auto-cycle are saved in EEPROM after a delay
// The RGB Shades will automatically start up with the last-selected settings
// 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 102
// Cycle time (milliseconds between pattern changes)
#define cycleTime 15000
// Hue time (milliseconds between hue increments)
#define hueTime 30
// Time after changing settings before settings are saved to EEPROM
#define EEPROMDELAY 2000
// Include FastLED library and other useful files
#include <FastLED.h>
#include <EEPROM.h>
#include "messages.h"
#include "font.h"
#include "XYmap.h"
#include "utils.h"
#include "effects.h"
#include "buttons.h"
// list of functions that will be displayed
functionList effectList[] = {threeSine,
threeDee,
scrollTextZero,
plasma,
confetti,
rider,
scrollTextOne,
glitter,
slantBars,
scrollTextTwo,
colorFill,
sideRain,
//pumpkin
};
const byte numEffects = (sizeof(effectList)/sizeof(effectList[0]));
// Runs one time at the start of the program (power up or reset)
void setup() {
// check to see if EEPROM has been used yet
// if so, load the stored settings
byte eepromWasWritten = EEPROM.read(0);
if (eepromWasWritten == 99) {
currentEffect = EEPROM.read(1);
autoCycle = EEPROM.read(2);
currentBrightness = EEPROM.read(3);
}
if (currentEffect > (numEffects - 1)) currentEffect = 0;
// write FastLED configuration data
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, LAST_VISIBLE_LED + 1);
// set global brightness value
FastLED.setBrightness( scale8(currentBrightness, MAXBRIGHTNESS) );
// configure input buttons
pinMode(MODEBUTTON, INPUT_PULLUP);
pinMode(BRIGHTNESSBUTTON, INPUT_PULLUP);
}
// 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
doButtons(); // perform actions based on button state
checkEEPROM(); // update the EEPROM if necessary
// 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
}