Skip to content

Commit 67a5054

Browse files
committed
Resin River Table
Arduino code for Resin Table guide
1 parent 2d1db52 commit 67a5054

1 file changed

Lines changed: 117 additions & 0 deletions

File tree

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Code by Erin St Blaine for Adafruit.com, based on FastLED animations by Mark Kriegsman
2+
3+
#include <Adafruit_CircuitPlayground.h>
4+
#include <FastLED.h>
5+
6+
// tell FastLED all about the Circuit Playground's layout
7+
8+
#define DATA_PIN A1 //LED data on pin A1
9+
#define NUM_LEDS 200 // total number of LEDs in your strip
10+
#define COLOR_ORDER GRB // color order -- change this if your colors are coming out wrong
11+
12+
uint8_t brightness = 150; // Set brightness level
13+
14+
int STEPS = 6; //makes the rainbow colors more or less spread out
15+
int NUM_MODES = 5; // change this number if you add or subtract modes
16+
int CYCLETIME = 60; // number of seconds on each mode, for mode cycling
17+
18+
CRGB leds[NUM_LEDS]; // set up an LED array
19+
20+
CRGBPalette16 currentPalette;
21+
TBlendType currentBlending;
22+
23+
int ledMode = 0; //Initial mode
24+
bool leftButtonPressed;
25+
bool rightButtonPressed;
26+
27+
28+
// SETUP -----------------------------------------------------
29+
void setup() {
30+
Serial.begin(57600);
31+
CircuitPlayground.begin();
32+
FastLED.addLeds<WS2812B, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip ); // Use this line if using neopixels
33+
currentBlending = LINEARBLEND;
34+
set_max_power_in_volts_and_milliamps(5, 5000); // FastLED 2.1 Power management set at 5V, 5000mA
35+
36+
37+
}
38+
39+
void loop() {
40+
41+
leftButtonPressed = CircuitPlayground.leftButton();
42+
rightButtonPressed = CircuitPlayground.rightButton();
43+
44+
if (leftButtonPressed) { //left button cycles through modes
45+
clearpixels();
46+
ledMode=ledMode+1;
47+
delay(300);
48+
if (ledMode > NUM_MODES){
49+
ledMode=0;
50+
}
51+
}
52+
if (rightButtonPressed) { // on off button
53+
ledMode=99;
54+
55+
}
56+
57+
switch (ledMode) {
58+
case 0: modeCycle(); break;
59+
case 1: currentPalette = RainbowColors_p; rainbow(); break;
60+
case 2: currentPalette = OceanColors_p; rainbow(); break;
61+
case 3: currentPalette = LavaColors_p; rainbow(); break;
62+
case 4: currentPalette = ForestColors_p; rainbow(); break;
63+
case 5: currentPalette = PartyColors_p; rainbow(); break;
64+
case 99: clearpixels(); break;
65+
66+
}
67+
}
68+
void clearpixels()
69+
{
70+
CircuitPlayground.clearPixels();
71+
for( int i = 0; i < NUM_LEDS; i++) {
72+
leds[i]= CRGB::Black;
73+
}
74+
FastLED.show();
75+
}
76+
77+
void rainbow()
78+
{
79+
80+
static uint8_t startIndex = 0;
81+
startIndex = startIndex + 1; /* motion speed */
82+
83+
FillLEDsFromPaletteColors( startIndex);
84+
85+
FastLED.show();
86+
FastLED.delay(20);
87+
88+
}
89+
90+
//this bit is in every palette mode, needs to be in there just once
91+
void FillLEDsFromPaletteColors( uint8_t colorIndex)
92+
{
93+
for( int i = 0; i < NUM_LEDS; i++) {
94+
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
95+
colorIndex += STEPS;
96+
}
97+
}
98+
99+
100+
int cycleMode=0;
101+
102+
void modeCycle()
103+
{
104+
switch (cycleMode) {
105+
case 0: currentPalette = RainbowColors_p; rainbow(); break;
106+
case 1: currentPalette = OceanColors_p; rainbow(); break;
107+
case 2: currentPalette = LavaColors_p; rainbow(); break;
108+
case 3: currentPalette = ForestColors_p; rainbow(); break;
109+
case 4: currentPalette = PartyColors_p; rainbow(); break;
110+
case 5: cycleMode=0; break;
111+
}
112+
113+
EVERY_N_SECONDS(CYCLETIME) {
114+
cycleMode++;
115+
}
116+
117+
}

0 commit comments

Comments
 (0)