#include <Adafruit_NeoPixel.h>
#define PIXELSPIN1 2
#define PIXELSPIN2 2
#define NUMPIXELS1 16
#define NUMPIXELS2 16
#define CALIBRATIONTIME 20000
Adafruit_NeoPixel pixels1 = Adafruit_NeoPixel(NUMPIXELS1, PIXELSPIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel pixels2 = Adafruit_NeoPixel(NUMPIXELS2, PIXELSPIN2, NEO_GRB + NEO_KHZ800);
const int numberOfSegments = 10;
const int segmentPins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
const int blinkLedPin = A1; // Pin for the first blink without delay
const int analogLedPin = A0; // Pin for the second blink without delay (analog pin 0)
const int relayPin = 13; // Pin for controlling the relay (analog pin 1)
// Timing intervals (in milliseconds)
unsigned long pixelsInterval1 = 100; // timing for White
unsigned long pixelsInterval2 = 100; // timing for Purple
unsigned long blinkInterval = 500; // timing for the first blink
unsigned long analogBlinkInterval = 300; // timing for the second blink
unsigned long relayOnTime = 60000; // NO state duration (60 seconds)
unsigned long relayOffTime = 10000; // NC state duration (10 seconds)
unsigned long theaterChase1PreviousMillis = 0;
unsigned long theaterChase2PreviousMillis = 0;
unsigned long blinkPreviousMillis = 0;
unsigned long analogBlinkPreviousMillis = 0;
unsigned long relayPreviousMillis = 0;
bool relayState = false; // false = NO, true = NC
unsigned long previousMillis = 0;
const long interval = 175; // Change this value to adjust the speed
int theaterChaseQ = 0;
uint16_t currentPixel = 0; // what pixel are we operating on
void setup() {
currentPixel = 0;
pixels1.begin();
pixels1.show();
pixels2.begin();
pixels2.show();
// Set the segment pins as OUTPUT
for (int i = 0; i < numberOfSegments; i++) {
pinMode(segmentPins[i], OUTPUT);
}
pinMode(blinkLedPin, OUTPUT); // Set the first blink LED pin as OUTPUT
pinMode(analogLedPin, OUTPUT); // Set the second blink LED pin as OUTPUT
pinMode(relayPin, OUTPUT); // Set the relay pin as OUTPUT
}
void loop() {
if ((unsigned long)(millis() - theaterChase1PreviousMillis) >= pixelsInterval1) {
theaterChase1PreviousMillis = millis();
theaterChase1(pixels1.Color(127, 127, 127)); // White
}
if ((unsigned long)(millis() - theaterChase2PreviousMillis) >= pixelsInterval2) {
theaterChase2PreviousMillis = millis();
theaterChase2(pixels2.Color(175, 51, 255)); // Purple
}
// Blink without delay for the first LED on pin 13
unsigned long currentMillis = millis();
if (currentMillis - blinkPreviousMillis >= blinkInterval) {
blinkPreviousMillis = currentMillis;
digitalWrite(blinkLedPin, !digitalRead(blinkLedPin)); // Toggle the state of the LED
}
// Blink without delay for the second LED on analog pin 0
if (currentMillis - analogBlinkPreviousMillis >= analogBlinkInterval) {
analogBlinkPreviousMillis = currentMillis;
digitalWrite(analogLedPin, !digitalRead(analogLedPin)); // Toggle the state of the LED
}
// Control the relay with specified timing
if (!relayState && (currentMillis - relayPreviousMillis >= relayOnTime)) {
relayPreviousMillis = currentMillis;
relayState = true; // Switch to NC state
digitalWrite(relayPin, HIGH); // Activate the relay
} else if (relayState && (currentMillis - relayPreviousMillis >= relayOffTime)) {
relayPreviousMillis = currentMillis;
relayState = false; // Switch to NO state
digitalWrite(relayPin, LOW); // Deactivate the relay
}
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
// Your logic to fill the bar graph goes here
// For example, incrementally turning on segments
static int filledSegments = 0;
if (filledSegments < numberOfSegments) {
digitalWrite(segmentPins[filledSegments], HIGH);
filledSegments++;
} else {
// Reset the bar graph when all segments are filled
filledSegments = 0;
// Turn off all segments
for (int i = 0; i < numberOfSegments; i++) {
digitalWrite(segmentPins[i], LOW);
}
}
}
}
// Theatre-style crawling lights Blue
void theaterChase1(uint32_t c) {
for (int i = 0; i < pixels1.numPixels(); i = i + 3) {
pixels1.setPixelColor(NUMPIXELS1 - (i + theaterChaseQ), c);
}
pixels1.show();
for (int i = 0; i < pixels1.numPixels(); i = i + 3) {
pixels1.setPixelColor(NUMPIXELS1 - (i + theaterChaseQ), 0);
}
theaterChaseQ++;
if (theaterChaseQ >= 3) theaterChaseQ = 0;
}
// Theatre-style crawling lights Red
void theaterChase2(uint32_t c) {
for (int i = 0; i < pixels2.numPixels(); i = i + 3) {
pixels2.setPixelColor(NUMPIXELS2 - (i + theaterChaseQ), c);
}
pixels2.show();
for (int i = 0; i < pixels2.numPixels(); i = i + 3) {
pixels2.setPixelColor(NUMPIXELS2 - (i + theaterChaseQ), 0);
}
theaterChaseQ++;
if (theaterChaseQ >= 3) theaterChaseQ = 0;
}