/**
accendere le ore, spegnere i minuti quando cambia l'ora
spegnere i minuti, accendere i minuti quando cambiano i minuti
int distanza dallo start
int numero di led da accendere dopo la distanza dallo start
*/
#include <FastLED.h>
#include <SevSeg.h>
#include "Button.h"
#include "Clock.h"
#include "config.h"
#define NUM_LEDS 123
#define LED_PIN 2
//int distance from start
//led map parola
//0-64 ore
//65-123 minuti
int LED_MAP_HOUR_0 [64]= {0,1,1,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int LED_MAP_HOUR_1[64]= {1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int LED_MAP_MINUTES [59]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
const int COLON_PIN = 13;
int hour_current_status=99;
CRGB leds[NUM_LEDS];
Button hourButton(A0);
Button minuteButton(A1);
Clock clock;
SevSeg sevseg;
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();
}
}
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(50);
Serial.begin(115200);
clock.begin();
hourButton.begin();
hourButton.set_repeat(500, 200);
minuteButton.begin();
minuteButton.set_repeat(500, 200);
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;
}
////////////////////////////////////////////START HERE////////////////////////////////////////
void loop() {
DateTime now = clock.now();
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.println();
switch (displayState) {
case DisplayClock:
clockState();
break;
}
if (now.hour()==0) {
updateLedStripHour(LED_MAP_HOUR_0,0);
}
if (now.hour()==1) {
updateLedStripHour(LED_MAP_HOUR_1,1);
}
}
void updateLedStripHour(int updateLedStripListHour[], int new_status) {
if(hour_current_status==new_status) {
return;
}
int n;
for(n=0;n<=63;n+=1) {
if (updateLedStripListHour[n]==1) {
leds[n] = CRGB::Red;
FastLED.show();
}
else if(updateLedStripListHour[n]==0) {
leds[n] = CRGB::Black;
FastLED.show();
}
}
hour_current_status=new_status;
}
void updateLedStripMinutes(int updateLedStripListMinutes[]) {
if(minutes_old_status==minutes_current_status) {
return;
}
int n;
for(n=0;n<=59;n+=1) {
if (updateLedStripListMinutes[n]==1) {
leds[n+64] = CRGB::Red;
FastLED.show();
}
else if(updateLedStripListMinutes[n]==0) {
leds[n] = CRGB::Black;
FastLED.show();
}
}
}
void turnOffAllStrip() {
int n=0;
for(n=0;n<=123;n+=1) {
leds[n] = CRGB::Black;
FastLED.show();
}
}