# include <Adafruit_NeoPixel.h>
# define PIN 6
# define NUMPIXELS 42
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
const int relay = 7; //relay control pin
// disney maths
# define NPASSES 6 // times around the ring
# define START 45 // starting delay
# define FINSH 15 // final delay
# define ACCLPASS 4 //
float delayIncrement = (START - ACCLPASS) / (1.0 * NPASSES * NUMPIXELS);
void setup() {
pinMode(relay,OUTPUT);
Serial.begin(115200);
pinMode(4, INPUT_PULLUP);
digitalWrite(relay, LOW);
pixels.begin();
pixels.show(); // Initialize all pixels to 'off'
delay(777);
Serial.println(delayIncrement, 5);
Serial.println(F("Not yet Read[ing] personal data on a MIFARE PICC:"));
}
void disney()
{
float delayFactor = START;
for (unsigned char pass = 0; pass < NPASSES; pass++) {
for (unsigned char ii = 0; ii < NUMPIXELS; ii++) {
for (unsigned char toff = 0; toff < NUMPIXELS; toff++)
pixels.setPixelColor(toff, 0x0);
unsigned char theLED = ii; // one direction
pixels.setPixelColor(theLED, pixels.Color(0,250,0));
pixels.show();
delay(delayFactor);
if (delayFactor > FINSH)
delayFactor -= delayIncrement;
if (delayFactor > FINSH)
delayIncrement *= 1.01; // growth
}
}
}
void disneyaccess()
{
// player.play(1);
for (unsigned char tt = 0; tt < NUMPIXELS; tt++)
pixels.setPixelColor(tt, pixels.Color(0,250,0));
pixels.show();
if (digitalRead(relay) == HIGH) {
digitalWrite(relay,LOW);
Serial.println("Relay off");
}
else {
digitalWrite(relay,HIGH);
Serial.println("Relay on");
}
}
void disneyOnOff(unsigned char turn)
{
for (unsigned char tt = 0; tt < NUMPIXELS; tt++)
pixels.setPixelColor(tt, turn ? pixels.Color(0,0xff,0) : pixels.Color(0,0,0));
pixels.show();
}
bool access; // set by pushbutton here, RFID later.
void loop() {
access = checkButton();
//idle white LED circling
IWLC(0); // attention to the idle machine
if (access) {
Serial.println("Authorized access");
disney();
// disney();
// disney();
disneyaccess();
// player.play(1);
delay(333);
disneyOnOff(0);
delay(333);
disneyOnOff(1);
delay(333);
disneyOnOff(0);
delay(333);
disneyOnOff(1);
delay(333);
Serial.println();
disneyOnOff(0);
IWLC(1); // reset the idle machine
delay(100);
}
access = false;
}
// idle machine - moves LED around the ring. call it frequently.
void IWLC(unsigned char reset)
{
# define IDLE_TICK_MSEC 33 // time between LED movements
static uint32_t lastTime;
uint32_t now = millis();
static int led_index = 0;
if (reset) {
led_index = 0;
return;
}
if (now - lastTime < IDLE_TICK_MSEC) // time to move the LED along?
return; // nope! nothing to do. yet.
lastTime = now;
// bump the LED. clockwise
led_index = led_index + 1; if (led_index >= NUMPIXELS) led_index = 0;
// bump the LED. anti-clockwise
// led_index = led_index - 1; if (led_index < 0) led_index = NUMPIXELS - 1;
for (int ii = 0; ii < NUMPIXELS; ii++) {
pixels.setPixelColor(ii, ii == led_index ? pixels.Color(200, 200, 200) : pixels.Color(0, 0, 0));
}
pixels.show();
}
/* hand made button debounce sets flag */
bool checkButton()
{
static unsigned long lastButtonTime;
static unsigned char lastButton = HIGH;
unsigned long now = millis();
bool returnCode = false;
if (now - lastButtonTime > 50) {
unsigned char thisButton = digitalRead(4);
if (thisButton != lastButton) {
if (!thisButton) {
Serial.println("I see the button");
returnCode = true;
}
lastButtonTime = now;
lastButton = thisButton;
}
}
return returnCode;
}