Skip to content

Instantly share code, notes, and snippets.

@yoursunny
Created December 23, 2024 01:50
Show Gist options
  • Save yoursunny/793f0496414c96295d842b0c8de28fcf to your computer and use it in GitHub Desktop.
Save yoursunny/793f0496414c96295d842b0c8de28fcf to your computer and use it in GitHub Desktop.
Christmas lights made from Adafruit MagTag https://youtu.be/mjqgy_R7W7M
// Hardware: Adafruit MagTag https://learn.adafruit.com/adafruit-magtag
// Compiler and Libraries:
// - Arduino IDE 2.3.4
// - ESP32 Arduino Core 3.0.7
// - Adafruit NeoPixel 1.12.3
// - Adafruit EPD 4.5.6
// Settings:
// - CPU Frequency: 40MHz
#include <Adafruit_NeoPixel.h>
#include <Adafruit_ThinkInk.h>
#include <Fonts/FreeSans24pt7b.h>
#include <Fonts/FreeSansOblique12pt7b.h>
Adafruit_NeoPixel strip(4, PIN_NEOPIXEL, NEO_GRB | NEO_KHZ800);
ThinkInk_290_Grayscale4_T5 display(EPD_DC, EPD_RESET, EPD_CS, -1, -1);
void updateStrip() {
static uint16_t pixelIndex = UINT16_MAX;
if (++pixelIndex >= strip.numPixels()) {
pixelIndex = 0;
}
strip.setPixelColor(pixelIndex, random(256), random(256), random(256));
strip.show();
}
const char* MESSAGES[]{
"tree stump inspector",
"We love thorns.",
"Have you logged a DNF?",
"rm -rf /*",
"Best we can do is $7.",
"Do you have routed /48?",
};
void drawMessage(int index) {
display.clearBuffer();
display.setTextColor(EPD_BLACK);
display.setFont(&FreeSans24pt7b);
display.setCursor(40, 40);
display.print("yoursunny");
display.setFont(&FreeSansOblique12pt7b);
display.setCursor(20, 120);
display.print(MESSAGES[index]);
display.display();
}
void changeMessage(int offset) {
static int index = 0;
int newIndex = index + offset;
if (newIndex >= 0 && newIndex < static_cast<int>(sizeof(MESSAGES) / sizeof(MESSAGES[0]))) {
index = newIndex;
drawMessage(index);
}
}
void setup() {
pinMode(SPEAKER_SHUTDOWN, OUTPUT);
digitalWrite(SPEAKER_SHUTDOWN, LOW);
display.begin(THINKINK_MONO);
drawMessage(0);
pinMode(14, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(NEOPIXEL_POWER, OUTPUT);
digitalWrite(NEOPIXEL_POWER, LOW);
strip.begin();
strip.setBrightness(50);
strip.show();
}
void loop() {
static int i = 0;
if (++i >= 1000) {
i = 0;
}
if (i % 50 == 0) {
updateStrip();
}
if (digitalRead(14) == LOW) {
changeMessage(-1);
while (digitalRead(14) == LOW) {
delay(1);
}
}
if (digitalRead(12) == LOW) {
changeMessage(+1);
while (digitalRead(12) == LOW) {
delay(1);
}
}
delay(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment