#include <WiFi.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(23, 22, 21, 19, 18, 5);
#define VERSION "v1.0"
#define RED 0
#define YELLOW 4
#define GREEN 2
#define ADMIN 16
#define dev 12
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
lcd.setCursor(15, 1);
lcd.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void clear() {
lcd.setCursor(0, 1);
lcd.println(" ");
}
void coolDownTest() {
digitalWrite(RED, HIGH);
lcd.setCursor(1, 1);
lcd.println("CoolDwn Active");
delay(1000);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(2, 1);
lcd.println("WarriorBorgs");
digitalWrite(RED, LOW);
}
void unknownUID() {
digitalWrite(RED, HIGH);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(3, 1);
lcd.println("Unknwn UID");
delay(1000);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(2, 1);
lcd.println("WarriorBorgs");
digitalWrite(RED, LOW);
}
void registerUID() {
digitalWrite(YELLOW, HIGH);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(1, 1);
lcd.println("Scan Admin tag");
delay(1000);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(2, 1);
lcd.println("Scan New UID");
delay(1000);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(0, 1);
lcd.println("Waiting for Dash");
delay(1000);
digitalWrite(GREEN, HIGH);
delay(500);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(2, 1);
lcd.println("WarriorBorgs");
}
void adminMenu() {
// "Select" points are at (0,1) register, and (9, 1) delete
digitalWrite(YELLOW, HIGH);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(1, 1);
lcd.println("Scan Admin tag");
delay(1000);
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(1, 1);
lcd.println("register");
lcd.setCursor(10, 1);
lcd.println("delete");
while(true){
lcd.setCursor(0,1);
lcd.blink();
float initTime = millis();
if (millis() - initTime >= 60000) {
lcd.setCursor(0, 1);
lcd.println(" ");
lcd.setCursor(1,1);
lcd.println("WarriorBorgs");
digitalWrite(YELLOW, LOW);
return;
}
}
}
void neoShowcase() {
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color( 0, 255, 0), 50); // Green
colorWipe(strip.Color( 0, 0, 255), 50); // Blue
// Do a theater marquee effect in various colors...
theaterChase(strip.Color(127, 127, 127), 50); // White, half brightness
theaterChase(strip.Color(127, 0, 0), 50); // Red, half brightness
theaterChase(strip.Color( 0, 0, 127), 50); // Blue, half brightness
rainbow(10); // Flowing rainbow cycle along the whole strip
theaterChaseRainbow(50); // Rainbow-enhanced theaterChase variant
}
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
// Theater-marquee-style chasing lights. Pass in a color (32-bit value,
// a la strip.Color(r,g,b) as mentioned above), and a delay time (in ms)
// between frames.
void theaterChase(uint32_t color, int wait) {
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this loop:
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
strip.rainbow(firstPixelHue);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
// Rainbow-enhanced theater marquee. Pass delay time (in ms) between frames.
void theaterChaseRainbow(int wait) {
int firstPixelHue = 0; // First pixel starts at red (hue 0)
for(int a=0; a<30; a++) { // Repeat 30 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in increments of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
// hue of pixel 'c' is offset by an amount to make one full
// revolution of the color wheel (range 65536) along the length
// of the strip (strip.numPixels() steps):
int hue = firstPixelHue + c * 65536L / strip.numPixels();
uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
firstPixelHue += 65536 / 90; // One cycle of color wheel over 90 frames
}
}
}
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(RED, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(ADMIN, INPUT_PULLUP);
pinMode(dev, INPUT_PULLUP);
Serial.begin(115200);
Adafruit_NeoPixel strip(16, 14, NEO_GRB + NEO_KHZ800);
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Connecting to ");
lcd.setCursor(0, 1);
lcd.print("WiFi ");
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(250);
spinner();
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
lcd.clear();
lcd.setCursor(0, 0);
lcd.println("Online");
lcd.setCursor(2, 1);
lcd.println("WarriorBorgs");
delay(500);
lcd.setCursor(12, 0);
lcd.println(VERSION);
Serial.println(" @@@@ @@ @@@@ @@@@@@@@@@@@@@@ ");
Serial.println(" @@@@ @ @@@@ @@@@@@@@@@@@@@@@ ");
Serial.println(" @@@@ @ @@@ @ @@@@ @@@ @ @@@@ ");
Serial.println(" @@@@ @@ @@@@@@@ @@ @@@@ @@@@ @ @@@@ ");
Serial.println(" @@@@ @ @@@@@@@@@ @@ @@@@ @@@@ @@@@@@ ");
Serial.println(" @@@@ @@@@@ @@@@ @@@@ @@@@@@@@@@@@@@@@@ ");
Serial.println(" @@@@ @@@@ @ @@@@ @@@@ @@@@@@@@@@@@@@@@@@@ ");
Serial.println(" @@@@@@@@ @ @@@@@@@@ @@@@ @@ @@@@");
Serial.println(" @@@@@@ @@ @@@@@@ @@@ @ @@@@");
Serial.println(" @@@@@ @@ @@@@@ @@@@@@@@@@@@@@@@@@@@@");
Serial.println(" @@@ @@ @@@@ @@@@@@@@@@@@@@@@@@@ ");
Serial.println("");
Serial.println("WarriorAttend System Initiated");
if (digitalRead(dev)) {
Serial.println("");
Serial.println("WarriorAttend Dev/Debug Command Interface");
Serial.println("-----------------------------------------");
Serial.println("R | Open UID registration dialog");
Serial.println("U | Simulate an unknown UID");
Serial.println("C | Simulate Cooldown Error");
Serial.println("A | Open Admin Dialog");
Serial.println("N | NeoPixel Showcase");
} else {
Serial.println("Dev mode not enabled, serial control disabled");
}
}
void loop() {
char command;
if (Serial.available()) {
if (digitalRead(dev)) {
command = Serial.read();
Serial.println(command);
switch (command) {
case 'R':
registerUID();
case 'U':
unknownUID();
case 'C':
coolDownTest();
case 'A':
adminMenu();
case 'N':
neoShowcase();
}
} else {
Serial.println("Dev mode not enabled - womp womp");
}
}
}