2021-12-31 15:58:27 -07:00
|
|
|
#include <FastLED.h>
|
2022-07-19 21:14:34 -06:00
|
|
|
#include <ArduinoHttpClient.h>
|
|
|
|
#include <WiFiClientSecure.h>
|
2022-01-01 09:35:06 -07:00
|
|
|
#include "picker.h"
|
2022-07-17 22:22:16 -06:00
|
|
|
#include "network.h"
|
2021-12-31 15:58:27 -07:00
|
|
|
|
2022-07-17 22:22:16 -06:00
|
|
|
#define NEOPIXEL_PIN 32
|
|
|
|
#define GRIDLEN 64
|
|
|
|
#define WFM_PASSWORD "artsy fartsy"
|
2022-07-19 21:14:34 -06:00
|
|
|
|
|
|
|
#define ART_HOSTNAME "sweetums.woozle.org"
|
|
|
|
#define ART_PORT 443
|
|
|
|
#define ART_PATH "/public/wallart.bin"
|
2021-12-31 15:58:27 -07:00
|
|
|
|
|
|
|
#define MILLISECOND 1
|
|
|
|
#define SECOND (1000 * MILLISECOND)
|
|
|
|
|
2022-07-19 21:14:34 -06:00
|
|
|
#define HTTPS_TIMEOUT (2 * SECOND)
|
|
|
|
|
2021-12-31 15:58:27 -07:00
|
|
|
CRGB grid[GRIDLEN];
|
|
|
|
|
2022-07-17 22:22:16 -06:00
|
|
|
void setup() {
|
|
|
|
FastLED.addLeds<WS2812, NEOPIXEL_PIN, GRB>(grid, GRIDLEN);
|
|
|
|
FastLED.setBrightness(32);
|
|
|
|
network_setup(WFM_PASSWORD);
|
|
|
|
}
|
|
|
|
|
2022-01-01 09:35:06 -07:00
|
|
|
void fade(int cycles = 2) {
|
|
|
|
int reps = (cycles*GRIDLEN) + random(GRIDLEN);
|
2021-12-31 15:58:27 -07:00
|
|
|
int hue = random(256);
|
|
|
|
for (int i = 0; i < reps; i++) {
|
|
|
|
for (int pos = 0; pos < 8; pos++) {
|
|
|
|
grid[(i+pos) % GRIDLEN] = CHSV(hue, 255, pos * 32);
|
|
|
|
}
|
|
|
|
FastLED.show();
|
2022-07-17 22:22:16 -06:00
|
|
|
pause(80);
|
2021-12-31 15:58:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-01 09:35:06 -07:00
|
|
|
void singleCursor(int count = 80) {
|
2022-07-17 22:22:16 -06:00
|
|
|
for (int i = 0; i < count; i++) {
|
2021-12-31 15:58:27 -07:00
|
|
|
grid[20] = CHSV(0, 210, 127 * (i%2));
|
|
|
|
FastLED.show();
|
2022-07-17 22:22:16 -06:00
|
|
|
pause(120);
|
2021-12-31 15:58:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NUM_SPARKS 3
|
2022-01-01 09:35:06 -07:00
|
|
|
void sparkle(int cycles=50) {
|
2022-07-18 07:42:52 -06:00
|
|
|
int pos[NUM_SPARKS] = {0};
|
|
|
|
|
|
|
|
for (int i = 0; i < cycles; i++) {
|
|
|
|
for (int j = 0; j < NUM_SPARKS; j++) {
|
|
|
|
grid[pos[j]] = CRGB::Black;
|
|
|
|
pos[j] = random(GRIDLEN);
|
|
|
|
grid[pos[j]] = CRGB::Gray;
|
|
|
|
}
|
|
|
|
FastLED.show();
|
|
|
|
pause(40);
|
|
|
|
}
|
2021-12-31 15:58:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NUM_GLITCH 4
|
|
|
|
#define GLITCH_FRAMES 64
|
2022-01-01 09:35:06 -07:00
|
|
|
void glitchPulse(int cycles=1000) {
|
2021-12-31 15:58:27 -07:00
|
|
|
int steps[NUM_GLITCH] = {0};
|
|
|
|
int pos[NUM_GLITCH] = {0};
|
|
|
|
CRGB color[NUM_GLITCH];
|
|
|
|
|
|
|
|
for (int i = 0; i < NUM_GLITCH; i++) {
|
|
|
|
steps[i] = GLITCH_FRAMES / NUM_GLITCH * i;
|
|
|
|
color[i] = CRGB::Brown;
|
|
|
|
}
|
|
|
|
|
2022-01-01 09:35:06 -07:00
|
|
|
for (int frame = 0; frame < cycles; frame++) {
|
2021-12-31 15:58:27 -07:00
|
|
|
for (int i = 0; i < NUM_GLITCH; i++) {
|
|
|
|
if (steps[i] == 0) {
|
|
|
|
steps[i] = GLITCH_FRAMES;
|
|
|
|
pos[i] = random(GRIDLEN);
|
|
|
|
color[i] = CHSV(random(256), 64 + random(64), 255);
|
|
|
|
}
|
|
|
|
CRGB c = color[i];
|
|
|
|
int bmask = (0xff * steps[i] / 32) & 0xff;
|
|
|
|
if (steps[i] == GLITCH_FRAMES/2) {
|
|
|
|
bmask = 0xff - bmask;
|
|
|
|
}
|
|
|
|
c.red &= bmask;
|
|
|
|
c.green &= bmask;
|
|
|
|
c.blue &= bmask;
|
|
|
|
grid[pos[i]] = c;
|
|
|
|
steps[i]--;
|
|
|
|
}
|
|
|
|
FastLED.show();
|
2022-07-17 22:22:16 -06:00
|
|
|
pause(100);
|
2021-12-31 15:58:27 -07:00
|
|
|
}
|
2022-01-01 09:35:06 -07:00
|
|
|
}
|
|
|
|
|
2022-07-17 22:22:16 -06:00
|
|
|
void conwayish(int cycles=5000) {
|
2022-01-01 09:35:06 -07:00
|
|
|
uint8_t total[GRIDLEN];
|
|
|
|
uint8_t left[GRIDLEN] = {0};
|
|
|
|
uint8_t hue = random(0, 64);
|
|
|
|
|
|
|
|
for (int i = 0; i < GRIDLEN; i++) {
|
|
|
|
total[i] = random(64, 256);
|
|
|
|
left[i] = total[i];
|
|
|
|
}
|
2021-12-31 15:58:27 -07:00
|
|
|
|
2022-01-01 09:35:06 -07:00
|
|
|
for (int frame = 0; frame < cycles; frame++) {
|
|
|
|
for (int i = 0; i < GRIDLEN; i++) {
|
|
|
|
if (left[i] == 0) {
|
|
|
|
left[i] = total[i];
|
|
|
|
if (grid[i].getLuma() == 0) {
|
|
|
|
grid[i].setHSV(hue, 180, 192);
|
|
|
|
} else {
|
|
|
|
grid[i] = CRGB::Black;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
left[i]--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FastLED.show();
|
2022-07-17 22:22:16 -06:00
|
|
|
pause(20);
|
2022-01-01 09:35:06 -07:00
|
|
|
}
|
2021-12-31 15:58:27 -07:00
|
|
|
}
|
|
|
|
|
2022-07-17 22:22:16 -06:00
|
|
|
void cm5(int cycles=200) {
|
|
|
|
for (int frame = 0; frame < cycles; frame++) {
|
|
|
|
int val = 127 * random(2);
|
|
|
|
for (int pos = 0; pos < GRIDLEN; pos++) {
|
|
|
|
if (pos < GRIDLEN-1) {
|
|
|
|
grid[pos] = grid[pos + 1];
|
|
|
|
} else {
|
|
|
|
grid[pos] = CHSV(0, 255, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FastLED.show();
|
|
|
|
pause(500);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Art from the network
|
2022-07-19 21:14:34 -06:00
|
|
|
int NetArtFrames = 0;
|
|
|
|
CRGB NetArt[8][GRIDLEN];
|
2022-07-17 22:22:16 -06:00
|
|
|
|
2022-07-19 21:14:34 -06:00
|
|
|
void netart(int count=40) {
|
|
|
|
if (NetArtFrames < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
memcpy(grid, NetArt[i%NetArtFrames], GRIDLEN*3);
|
2022-07-17 22:22:16 -06:00
|
|
|
FastLED.show();
|
2022-07-19 21:14:34 -06:00
|
|
|
pause(500);
|
2022-07-17 22:22:16 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 21:14:34 -06:00
|
|
|
uint8_t netgetStatus(uint8_t hue) {
|
2022-07-17 22:22:16 -06:00
|
|
|
static int positions[4] = {0};
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
grid[positions[j]] = CHSV(0, 0, 0);
|
|
|
|
positions[j] = random(GRIDLEN);
|
|
|
|
grid[positions[j]] = CHSV(hue, 255, 180);
|
|
|
|
}
|
|
|
|
FastLED.show();
|
|
|
|
pause(500);
|
|
|
|
return hue;
|
2021-12-31 15:58:27 -07:00
|
|
|
}
|
|
|
|
|
2022-07-19 21:14:34 -06:00
|
|
|
void netget(int count=60) {
|
|
|
|
uint8_t hue = netgetStatus(HUE_BLUE);
|
2022-07-17 22:22:16 -06:00
|
|
|
|
|
|
|
if (connected()) {
|
|
|
|
WiFiClientSecure scli;
|
|
|
|
|
|
|
|
hue = netgetStatus(hue - 32);
|
|
|
|
scli.setInsecure();
|
|
|
|
|
2022-07-19 21:14:34 -06:00
|
|
|
HttpClient https(scli, ART_HOSTNAME, ART_PORT);
|
|
|
|
do {
|
|
|
|
if (https.get(ART_PATH) != 0) break;
|
|
|
|
hue = netgetStatus(hue - 32);
|
|
|
|
|
|
|
|
if (https.skipResponseHeaders() != HTTP_SUCCESS) break;
|
|
|
|
hue = netgetStatus(hue - 32);
|
|
|
|
|
|
|
|
int artlen = https.read((uint8_t *)NetArt, sizeof(NetArt));
|
|
|
|
hue = netgetStatus(hue - 32);
|
|
|
|
NetArtFrames = (artlen / 3) / GRIDLEN;
|
|
|
|
} while(false);
|
|
|
|
https.stop();
|
2022-07-17 22:22:16 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
netgetStatus(hue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-18 07:43:19 -06:00
|
|
|
const int spinner_pos[4] = {27, 28, 36, 35};
|
|
|
|
void spinner(int count=32) {
|
2022-07-18 07:42:52 -06:00
|
|
|
for (int i = 0; i < count; i++) {
|
2022-07-18 07:43:19 -06:00
|
|
|
int pos = spinner_pos[i % 4];
|
2022-07-18 07:42:52 -06:00
|
|
|
grid[pos] = CRGB::OliveDrab;
|
|
|
|
FastLED.show();
|
|
|
|
pause(125);
|
|
|
|
grid[pos] = CRGB::Black;
|
|
|
|
}
|
|
|
|
}
|
2022-07-17 22:22:16 -06:00
|
|
|
|
2021-12-31 15:58:27 -07:00
|
|
|
void loop() {
|
2022-07-17 22:22:16 -06:00
|
|
|
Picker p;
|
|
|
|
|
|
|
|
if (p.Pick(1)) {
|
|
|
|
fade();
|
|
|
|
singleCursor(20);
|
|
|
|
} else if (p.Pick(1)) {
|
|
|
|
sparkle();
|
|
|
|
} else if (p.Pick(4)) {
|
|
|
|
singleCursor();
|
|
|
|
} else if (p.Pick(8)) {
|
|
|
|
conwayish();
|
|
|
|
} else if (p.Pick(8)) {
|
|
|
|
glitchPulse();
|
|
|
|
} else if (p.Pick(8)) {
|
|
|
|
cm5();
|
2022-07-19 21:14:34 -06:00
|
|
|
} else if (p.Pick(8)) {
|
|
|
|
netart();
|
2022-07-17 22:22:16 -06:00
|
|
|
} else if (p.Pick(4) || !connected()) {
|
|
|
|
netget();
|
|
|
|
}
|
|
|
|
}
|