#include "Key.h"
#include "Keypad.h"
#include "LiquidCrystal_I2C.h"
#include "Adafruit_NeoPixel.h"
#define PIXEL_COUNT 40
#define DATA_PIN 3
int count=0;
int countA = 0;
int countB = 0;
int countC = 0;
int countD = 0;
int timer=0;
int i=0;
char array[]={' ',' ',' ',' '};
String str;
unsigned long time=0;
unsigned long countdown=0;
Adafruit_NeoPixel strip(PIXEL_COUNT, DATA_PIN, NEO_GRB + NEO_KHZ800);
LiquidCrystal_I2C lcd(0x27,16,2);
const byte ROWS=4;
const byte COLS=4;
byte rowPins[ROWS] = {11,10,9,8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7,6,5,4}; //connect to the column pinouts of the keypad
char hexaKeys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
//initialize an instance of class NewKeypad
Keypad myKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Color:");
lcd.setCursor(0,1);
lcd.print("Duration:");
strip.begin();
strip.show();
Serial.begin(9600);
}
void showColor(uint32_t color) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
}
}
void loop() {
Serial.println(count);
char symbol=myKeypad.getKey();
delay(10);
if (symbol) {
if (symbol=='A') {
countA++;
countB=0;
countC=0;
countD=0;
switch (countA) {
case 1:
lcd.setCursor(6,0);
lcd.print("Red ");
break;
case 2:
lcd.setCursor(6,0);
lcd.print("Green ");
break;
case 3:
lcd.setCursor(6,0);
lcd.print("Blue ");
break;
case 4:
lcd.setCursor(6,0);
lcd.print("Yellow ");
break;
case 5:
lcd.setCursor(6,0);
lcd.print("Pink ");
break;
case 6:
lcd.setCursor(6,0);
lcd.print("Teal ");
break;
case 7:
lcd.setCursor(6,0);
lcd.print("White ");
break;
default:
countA=0;
lcd.setCursor(6,0);
lcd.print(" ");
break;
}
}
else if (symbol=='B') {
countB++;
countA=0;
countC=0;
countD=0;
switch (countB) {
case 1:
lcd.setCursor(6,0);
lcd.print("Red-Green ");
break;
default:
countB=0;
lcd.setCursor(6,0);
lcd.print(" ");
break;
}
}
else if (symbol=='C') {
countC++;
countA=0;
countB=0;
countD=0;
switch (countC) {
case 1:
lcd.setCursor(6,0);
lcd.print("Red-Green ");
break;
default:
countC=0;
lcd.setCursor(6,0);
lcd.print(" ");
break;
}
}
else if (symbol=='D') {
countD++;
countA=0;
countB=0;
countC=0;
switch (countD) {
case 1:
lcd.setCursor(6,0);
lcd.print("Green-Blue");
break;
default:
countD=0;
lcd.setCursor(6,0);
lcd.print(" ");
break;
}
}
else if (symbol=='*') {
count=0;
}
else if (symbol=='#') {
count=1;
}
else {
array[i]=symbol;
str += array[i];
timer = str.toInt();
lcd.setCursor(9,1);
lcd.print(timer);
i++;
if (i>=4) {
i=0;
memset(array, 0, sizeof(array));
str == ' ';
timer=0;
lcd.setCursor(9,1);
lcd.print(timer);
}
}
}
delay(10);
if (count=1) {
lcd.setCursor(14,1);
lcd.print("ON");
if (millis()-countdown>=60000) {
countdown=millis();
timer--;
lcd.setCursor(9,1);
lcd.print(timer);
}
delay(10);
switch (countA) {
case 1:
showColor(strip.Color(255,0,0));
break;
case 2:
showColor(strip.Color(0,255,0));
break;
case 3:
showColor(strip.Color(0,0,255));
break;
case 4:
showColor(strip.Color(255,255,0));
break;
case 5:
showColor(strip.Color(255,0,255));
break;
case 6:
showColor(strip.Color(0,255,255));
break;
case 7:
showColor(strip.Color(255,255,255));
break;
default:
showColor(strip.Color(0,0,0));
break;
}
switch (countB) {
case 1:
if (millis()-time<=1000) {
showColor(strip.Color(255,0,0));
}
else if (millis()-time>1000 && millis()-time<=2000) {
showColor(strip.Color(0,255,0));
}
else {
time=millis();
}
break;
default:
showColor(strip.Color(0,0,0));
break;
}
switch (countC) {
case 1:
if (millis()-time<=1000) {
showColor(strip.Color(255,0,0));
}
else if (millis()-time>1000 && millis()-time<=2000) {
showColor(strip.Color(0,0,255));
}
else {
time=millis();
}
break;
default:
showColor(strip.Color(0,0,0));
break;
}
switch (countD) {
case 1:
if (millis()-time<=1000) {
showColor(strip.Color(0,255,0));
}
else if (millis()-time>1000 && millis()-time<=2000) {
showColor(strip.Color(0,0,255));
}
else {
time=millis();
}
break;
default:
showColor(strip.Color(0,0,0));
break;
}
if (timer=0) {
count=0;
}
}
else if (count=0) {
lcd.setCursor(13,1);
lcd.print("OFF");
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(" ");
showColor(strip.Color(0,0,0));
memset(array, 0, sizeof(array));
countA=0;
countB=0;
countC=0;
countD=0;
i=0;
time=0;
timer=0;
}
}