#include "SevSeg.h"
SevSeg sevseg;
int LDR1pin = A0;
int LDR2pin = A1;
#define HELLO_MAX_NUM_STR 9
#define MAX_STR_SIZE 4
char HELLO[HELLO_MAX_NUM_STR][MAX_STR_SIZE];
#define BYE_MAX_NUM_STR 7
char BYE[BYE_MAX_NUM_STR][MAX_STR_SIZE];
#define PATTERN_CHANGE_TIME 500/2
unsigned long timer = millis() - PATTERN_CHANGE_TIME;
byte STRPos1 = 0;
byte STRPos2 = 0;
void setup() {
byte numDigits = 4;
byte digitPins[] = {9, 10, 11, 12};
byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 13};
bool resistorsOnSegments = false;
byte hardwareConfig = COMMON_CATHODE;
bool updateWithDelays = false;
bool leadingZeros = false;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
sevseg.setBrightness(10);
strcpy(HELLO[1], "O ");
strcpy(HELLO[2], "LO ");
strcpy(HELLO[3], "LLO ");
strcpy(HELLO[4], "ELLO");
strcpy(HELLO[5], "HELL");
strcpy(HELLO[6], " HEL");
strcpy(HELLO[7], " HE");
strcpy(HELLO[8], " H");
strcpy(BYE[0], " B");
strcpy(BYE[1], " BY");
strcpy(BYE[2], " BYE");
strcpy(BYE[3], "BYE ");
strcpy(BYE[4], "YE ");
strcpy(BYE[5], "E ");
strcpy(BYE[6], "");
}
void loop() {
int LDR1 = analogRead(LDR1pin);
int LDR2 = analogRead(LDR2pin);
if (LDR1 <= 200 && LDR2 > 300){
STRPos2 = 0;
if (millis() > (timer + PATTERN_CHANGE_TIME)) {
sevseg.setChars(HELLO[STRPos1]);
STRPos1++;
if (STRPos1 >= HELLO_MAX_NUM_STR) STRPos1 = 0;
timer = millis();
}
} else if (LDR2 <= 300 && LDR1 > 300){
STRPos1 = 1;
if (millis() > (timer + PATTERN_CHANGE_TIME)) {
sevseg.setChars(BYE[STRPos2]);
STRPos2++;
if (STRPos2 >= BYE_MAX_NUM_STR) STRPos2 = 0;
timer = millis();
}
} else {
STRPos1 = 0;
STRPos2 = 0;
sevseg.setChars(" ");
}
sevseg.refreshDisplay();
}