Fix for 2020, hopefully
This commit is contained in:
parent
da1899c6a3
commit
67008e8502
|
@ -1,20 +1,36 @@
|
||||||
#include <Adafruit_NeoPixel.h>
|
#if defined(__AVR_ATtiny85__)
|
||||||
#include <EEPROM.h>
|
#define TINY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <FastLED.h>
|
||||||
#include "bounce2.h"
|
#include "bounce2.h"
|
||||||
#include "morse.h"
|
#include "morse.h"
|
||||||
|
|
||||||
// Do you want it to run forever, or cycle every 24 hours?
|
// Do you want it to run forever, or cycle every 24 hours?
|
||||||
|
#ifdef TINY
|
||||||
|
#define FOREVER true
|
||||||
|
#else
|
||||||
#define FOREVER false
|
#define FOREVER false
|
||||||
|
#endif
|
||||||
|
|
||||||
// Which pin your LED strip is connected to
|
// Which pin your LED strip is connected to
|
||||||
|
#ifdef TINY
|
||||||
|
#define NEOPIXEL_PIN 3
|
||||||
|
#else
|
||||||
#define NEOPIXEL_PIN 6
|
#define NEOPIXEL_PIN 6
|
||||||
|
#endif
|
||||||
|
|
||||||
// Which pin has the momentary switch to toggle full white.
|
// Which pin has the momentary switch to toggle full white.
|
||||||
#define BUTTON_PIN 4
|
#define BUTTON_PIN 4
|
||||||
|
|
||||||
// How many LEDs you have. It's okay if this is too big.
|
// How many LEDs you have. It's okay if this is too big.
|
||||||
#define LEDS_PER_GROUP 10
|
#define LEDS_PER_GROUP 10
|
||||||
|
#ifdef TINY
|
||||||
|
#define NUM_GROUPS 7
|
||||||
|
#else
|
||||||
#define NUM_GROUPS 20
|
#define NUM_GROUPS 20
|
||||||
|
#endif
|
||||||
|
#define NUM_LEDS (LEDS_PER_GROUP * NUM_GROUPS)
|
||||||
|
|
||||||
// How many milliseconds between activity in one group
|
// How many milliseconds between activity in one group
|
||||||
#define DELAY_MS 600
|
#define DELAY_MS 600
|
||||||
|
@ -48,13 +64,11 @@
|
||||||
#define ON_FOR (5 * HOUR)
|
#define ON_FOR (5 * HOUR)
|
||||||
|
|
||||||
const char *messages[] = {
|
const char *messages[] = {
|
||||||
"happy holiday ARK",
|
"seasons greetings",
|
||||||
"seasons greetings ARK",
|
"happy holiday",
|
||||||
"happy festivus ARK",
|
"merry xmas",
|
||||||
"merry christmas ARK",
|
"happy new year",
|
||||||
"hanukkah sameach ARK",
|
"CQ CQ OF9X",
|
||||||
"happy solstice ARK",
|
|
||||||
"happy new year ARK",
|
|
||||||
};
|
};
|
||||||
const int nmessages = sizeof(messages) / sizeof(*messages);
|
const int nmessages = sizeof(messages) / sizeof(*messages);
|
||||||
|
|
||||||
|
@ -77,18 +91,13 @@ const uint32_t colors[] = {
|
||||||
};
|
};
|
||||||
const int ncolors = sizeof(colors) / sizeof(*colors);
|
const int ncolors = sizeof(colors) / sizeof(*colors);
|
||||||
|
|
||||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_GROUPS * LEDS_PER_GROUP, NEOPIXEL_PIN, NEO_RGB | NEO_KHZ800);
|
CRGB leds[NUM_LEDS];
|
||||||
Bounce button;
|
Bounce button;
|
||||||
|
|
||||||
int mode;
|
|
||||||
int nextMode;
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
strip.begin();
|
FastLED.addLeds<WS2812, NEOPIXEL_PIN, RGB>(leds, NUM_LEDS);
|
||||||
strip.show();
|
|
||||||
button.attach(BUTTON_PIN, INPUT_PULLUP);
|
button.attach(BUTTON_PIN, INPUT_PULLUP);
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
mode = EEPROM.read(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool strandUpdate(bool white) {
|
bool strandUpdate(bool white) {
|
||||||
|
@ -109,9 +118,9 @@ bool strandUpdate(bool white) {
|
||||||
} else {
|
} else {
|
||||||
color = colors[random(ncolors)];
|
color = colors[random(ncolors)];
|
||||||
}
|
}
|
||||||
strip.setPixelColor(pos, color);
|
leds[pos] = color;
|
||||||
} else {
|
} else {
|
||||||
strip.setPixelColor(pos, 0);
|
leds[pos] = 0;
|
||||||
}
|
}
|
||||||
group = (group + 1) % NUM_GROUPS;
|
group = (group + 1) % NUM_GROUPS;
|
||||||
|
|
||||||
|
@ -122,19 +131,32 @@ bool strandUpdate(bool white) {
|
||||||
bool morseUpdate() {
|
bool morseUpdate() {
|
||||||
static MorseEncoder enc;
|
static MorseEncoder enc;
|
||||||
static unsigned long nextEventMillis = 0;
|
static unsigned long nextEventMillis = 0;
|
||||||
|
static bool ARK = true;
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
|
||||||
if (now >= nextEventMillis) {
|
if (now >= nextEventMillis) {
|
||||||
nextEventMillis = now + DIT_DURATION_MS;
|
nextEventMillis = now + DIT_DURATION_MS;
|
||||||
if (!enc.Tick()) {
|
if (!enc.Tick()) {
|
||||||
char *message = messages[random(nmessages)];
|
ARK = !ARK;
|
||||||
enc.SetText(message);
|
if (ARK) {
|
||||||
enc.Quiet(200);
|
enc.SetText("ARK");
|
||||||
|
enc.Quiet(MORSE_PAUSE_WORD);
|
||||||
|
} else {
|
||||||
|
#ifdef TINY
|
||||||
|
// I have tried twenty different ways to make this work on the ATTINY,
|
||||||
|
// including a big switch statement. It always freezes the program.
|
||||||
|
// I give up. Maybe it's a compiler bug having to do with a modulo.
|
||||||
|
enc.SetText(messages[0]);
|
||||||
|
#else
|
||||||
|
enc.SetText(messages[now % nmessages]);
|
||||||
|
#endif
|
||||||
|
enc.Quiet(200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
strip.setPixelColor(MORSE_PIXEL, enc.Transmitting ? MORSE_COLOR : 0);
|
leds[MORSE_PIXEL] = enc.Transmitting ? MORSE_COLOR : 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +168,7 @@ bool black() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
strip.clear();
|
FastLED.clear();
|
||||||
|
|
||||||
nextEventMillis = now + (DELAY_MS / NUM_GROUPS); // Keep timing consistent
|
nextEventMillis = now + (DELAY_MS / NUM_GROUPS); // Keep timing consistent
|
||||||
return true;
|
return true;
|
||||||
|
@ -169,7 +191,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
strip.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// blink the heart for a little bit
|
// blink the heart for a little bit
|
||||||
|
|
28
morse.h
28
morse.h
|
@ -16,22 +16,22 @@ class MorseEncoder {
|
||||||
*/
|
*/
|
||||||
void SetText(const char *s);
|
void SetText(const char *s);
|
||||||
|
|
||||||
/** Tick tells the encoder that a dit has elapsed.
|
/** Tick tells the encoder that a dit has elapsed.
|
||||||
*
|
*
|
||||||
* Returns true if there's data left to transmit.
|
* Returns true if there's data left to transmit.
|
||||||
* If it returns false, you need to feed it more data.
|
* If it returns false, you need to feed it more data.
|
||||||
*
|
*
|
||||||
* You should call this every time your dit duration ends.
|
* You should call this every time your dit duration ends.
|
||||||
*/
|
*/
|
||||||
bool Tick();
|
bool Tick();
|
||||||
|
|
||||||
/** Quiet stops transmitting for this many ticks.
|
/** Quiet stops transmitting for this many ticks.
|
||||||
*/
|
*/
|
||||||
void Quiet(int ticks);
|
void Quiet(int ticks);
|
||||||
|
|
||||||
/** Transmitting is true if you should be transmitting right now.
|
/** Transmitting is true if you should be transmitting right now.
|
||||||
*/
|
*/
|
||||||
bool Transmitting;
|
bool Transmitting;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *p;
|
const char *p;
|
||||||
|
|
Loading…
Reference in New Issue