#include <FastLED.h>
#include <SevSeg.h>
#include "Button.h"
#include "Clock.h"
#include "config.h"
#include <Servo.h>
#define NUM_LEDS 10
#define LED_PIN 2
#define purple CRGB(0x8010ff) // Purple
#define green CRGB(0x00ff00) // Green
#define gold CRGB(0xffd700) // Gold
#define white CRGB(0xffffff) // White
#define red CRGB(0xff0000) // Red
#define blue CRGB(0x0000ff) // Blue
#define orange CRGB(0xff8c00) // Orange
#define lightblue CRGB(0x33ffff) // Lightblue
CRGB streakcolor=white;
int colorStatus=0;
Servo servo_h1;
Servo servo_h2;
Servo servo_m1;
Servo servo_m2;
int pos_h1 = 0;
int pos_h2 = 0;
int pos_m1 = 0;
int pos_m2 = 0;
const int COLON_PIN = 13;
int hour_current_status=99;
CRGB leds[NUM_LEDS];
Button hourButton(A0);
Button minuteButton(A1);
Button modalityButton(A2);
Button luminosityButton(A3);
Clock clock;
SevSeg sevseg;
int val;
int modality = 0;
int inputPin = 3;
int current_h_am=99;
int current_h_pm=99;
int end_m=-99;
int minStatus=0;
int lumens=35;
char charMinute1;
char charMinute2;
char charHour1;
char charHour2;
int intMinute1;
int intMinute2;
int intHour1;
int intHour2;
enum DisplayState {
DisplayClock,
};
DisplayState displayState = DisplayClock;
long lastStateChange = 0;
void changeDisplayState(DisplayState newValue) {
displayState = newValue;
lastStateChange = millis();
}
long millisSinceStateChange() {
return millis() - lastStateChange;
}
void setColon(bool value) {
digitalWrite(COLON_PIN, value ? LOW : HIGH);
}
void clockState() {
if (hourButton.pressed()) {
clock.incrementHour();
}
if (minuteButton.pressed()) {
clock.incrementMinute();
}
if (modalityButton.pressed()) {
switch (modality){
case 0:
modality=1;
FastLED.setBrightness(0);
FastLED.show();
break;
case 1:
modality=0;
FastLED.setBrightness(lumens);
FastLED.show();
break;
}
}
if (luminosityButton.pressed()) {
switch (lumens){
case 5:
if(streakcolor==purple)
{
streakcolor=green;
updateLedStripColor(streakcolor);
}
else if(streakcolor==green)
{
streakcolor=gold;
updateLedStripColor(streakcolor);
}
else if(streakcolor==gold)
{
streakcolor=white;
updateLedStripColor(streakcolor);
}
else if(streakcolor==white)
{
streakcolor=red;
updateLedStripColor(streakcolor);
}
else if(streakcolor==red)
{
streakcolor=blue;
updateLedStripColor(streakcolor);
}
else if(streakcolor==blue)
{
streakcolor=orange;
updateLedStripColor(streakcolor);
}
else if(streakcolor==orange)
{
streakcolor=purple;
updateLedStripColor(streakcolor);
}
lumens=10;
break;
case 10:
lumens=15;
break;
case 15:
lumens=20;
break;
case 20:
lumens=25;
break;
case 25:
lumens=30;
break;
case 30:
lumens=35;
break;
case 35:
lumens=5;
break;
}
FastLED.setBrightness(lumens);
FastLED.show();
}
if (modality==1) {
val = digitalRead(inputPin);
if (val == HIGH) {
FastLED.setBrightness(lumens);
FastLED.show();
}
if (val == LOW) {
FastLED.setBrightness(0);
FastLED.show();
}
if (modality==0)
{
FastLED.show();
}
}
}
void setup() {
servo_h1.attach(4);
servo_h2.attach(7);
servo_m1.attach(0);
servo_m2.attach(1);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(lumens);
clock.begin();
hourButton.begin();
hourButton.set_repeat(500, 200);
minuteButton.begin();
minuteButton.set_repeat(500, 200);
modalityButton.begin();
modalityButton.set_repeat(500, 200);
luminosityButton.begin();
luminosityButton.set_repeat(500, 200);
pinMode(inputPin, INPUT);
pinMode(COLON_PIN, OUTPUT);
byte digits = 4;
byte digitPins[] = {2, 3, 4, 5};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12};
bool resistorsOnSegments = false;
bool updateWithDelays = false;
bool leadingZeros = true;
bool disableDecPoint = true;
updateLedStripOn(0,10);
}
////////////////////////////////////////////START HERE////////////////////////////////////////
void loop() {
clockState();
showTimeOnWhell();
}
void showTimeOnWhell() {
DateTime now = clock.now();
String stringMinute = String(now.minute());
int minutesLen=stringMinute.length();
if (minutesLen<2) {
charMinute1 = stringMinute[0];
}
else {
charMinute1 = stringMinute[0];
charMinute2 = stringMinute[1];
}
intMinute1 = charMinute1 - '0';
intMinute2 = charMinute2 - '0';
String stringHour = String(now.hour());
int hourLen=stringHour.length();
if (hourLen<2) {
charHour1 = stringHour[0];
}
else {
charHour1 = stringHour[0];
charHour1 = stringHour[1];
}
intHour1 = charHour1 - '0';
intHour2 = charHour2 - '0';
if(intMinute1==0) {
}
if(intMinute1==1) {
}
if(intMinute1==2) {
}
if(intMinute1==3) {
}
if(intMinute1==4) {
}
if(intMinute1==5) {
}
if(intMinute2==0) {
}
if(intMinute2==1) {
}
if(intMinute2==2) {
}
if(intMinute2==3) {
}
if(intMinute2==4) {
}
if(intMinute2==5) {
}
if(intMinute2==6) {
}
if(intMinute2==7) {
}
if(intMinute2==8) {
}
if(intMinute2==9) {
}
if(intHour1==0) {
}
if(intHour1==1) {
}
if(intHour1==2) {
}
if(intHour2==0) {
}
if(intHour2==1) {
}
if(intHour2==2) {
}
if(intHour2==3) {
}
if(intHour2==4) {
}
if(intHour2==5) {
}
if(intHour2==6) {
}
if(intHour2==7) {
}
if(intHour2==8) {
}
if(intHour2==9) {
}
}
void updateLedStripOn(int start_at, int lenght) {
int n;
for(n=start_at;n<start_at+lenght;n+=1) {
leds[n] = streakcolor;
FastLED.show();
}
}
void updateLedStripOff(int start_at, int lenght) {
int n;
for(n=start_at;n<start_at+lenght;n+=1) {
leds[n] = CRGB::Black;
FastLED.show();
}
}
void updateLedStripColor(CRGB streakcolor){
int n;
for(n=0;n<140;n+=1) {
leds[n] = streakcolor;
}
FastLED.show();
}