#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
const byte TFS = 7;
const byte BFS = 2;
const byte statusLED = 10;
const byte relay = A5;
byte RelayState;
#define LED_PIN 6
#define LED_COUNT 17
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
unsigned long previousMillis = 0;
unsigned long intervalOn = 1 * 1000; // 1 seconds on life too short!
unsigned long intervalOff = 3 * 1000; // 3 seconds off
unsigned long interval = intervalOn; // start with pump on
boolean status = false; //true = on; false = off
void setup() {
Serial.begin(9600);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
pinMode (TFS, INPUT_PULLUP);
pinMode (BFS, INPUT_PULLUP);
pinMode(relay, OUTPUT);
pinMode(statusLED, OUTPUT);
strip.begin();
strip.show();
strip.setBrightness(150); // Set BRIGHTNESS to about 1/5 (max = 255)
}
void loop() {
unsigned long currentMillis = millis();
delay(50);
if (!status) {
if (currentMillis - previousMillis >= intervalOff) {
previousMillis = currentMillis;
status = true;
}
else {
status = false;
}
}
else {
if (currentMillis - previousMillis >= intervalOn) {
previousMillis = currentMillis;
status = false;
}
else {
status = true;
}
}
digitalWrite(statusLED, status ? HIGH : LOW);
if (digitalRead (BFS) == HIGH && digitalRead (TFS) == HIGH) {
if (status) {
RelayState = HIGH;
colorWipe(strip.Color(0, 255, 0), 50); // Green
}
}
if (digitalRead (BFS) == HIGH && digitalRead (TFS) == LOW) {
if (status) {
RelayState = HIGH;
colorWipe(strip.Color(0, 0, 255), 50); // Blue
}
}
if (digitalRead (BFS) == LOW && digitalRead (TFS) == HIGH) {
RelayState = LOW;
colorWipe(strip.Color(255, 0, 0), 50); // red
}
if (digitalRead (BFS) == LOW && digitalRead (TFS) == LOW) {
RelayState = LOW;
colorWipe(strip.Color(255, 0, 0), 50); // red
}
digitalWrite(relay, RelayState);
}
void colorWipe(uint32_t color, int wait) {
static unsigned long lastSaidColor;
if (color != lastSaidColor) {
Serial.print("strip ");
switch (color) {
case 0xff0000 :
Serial.println("RED");
break;
case 0x00ff00 :
Serial.println("GREEN");
break;
case 0x0000ff :
Serial.println("BLUE");
break;
}
lastSaidColor = color;
}
}
void colorWipeX(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
}
}