Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <FastLED.h>
- #include <Wire.h>
- #include <DS3232RTC.h>
- #include <Time.h>
- #include <Timezone.h>
- #include <Math.h>
- // LCD setup
- LiquidCrystal lcd(10, 8, 9, 4, 5, 6, 7);
- // FastLED setup
- #define NUM_LEDS 60
- #define DATA_PIN 3
- CRGB leds[NUM_LEDS];
- int LDRPin = A3; // Pin for LDR
- // TimeZone setup
- TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //Central European Summer Time
- TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; //Central European Standard Time
- Timezone CE(CEST, CET);
- TimeChangeRule *tcr; //pointer to the time change rule, use to get the TZ abbrev
- time_t local;
- word mill = 0;
- unsigned long last_time = millis();
- uint8_t last_second;
- const uint8_t map_pixel_time[80] = {20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
- 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
- 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
- 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
- 30, 31, 32, 33, 34, 35, 36, 37, 38, 39};
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- setSyncProvider(RTC.get); // the function to get the time from the RTC
- setSyncInterval(1);
- last_second = second(local);
- lcd.begin(16, 2);
- }
- // Read temperature
- void read_temp() {
- if ( second(local) == 0) {
- Serial.print(RTC.temperature() / 4.);
- Serial.write(176);
- Serial.println("C");
- }
- }
- void draw_second(int pos, uint8_t hue) {
- leds[ map_pixel_time[pos - 2]] += CHSV( hue, 255, 255 - mill);
- leds[ map_pixel_time[pos - 1]] += CHSV( hue, 255, 255); // mid
- leds[ map_pixel_time[pos]] += CHSV( hue, 255, 255 ); // mid
- leds[ map_pixel_time[pos + 1]] += CHSV( hue, 255, 255 ); // mid
- leds[ map_pixel_time[pos + 2]] += CHSV( hue, 255, 255 ); // mid
- leds[ map_pixel_time[pos + 3]] += CHSV( hue, 255, mill);
- }
- void draw_minute(int pos, uint8_t hue) {
- leds[ map_pixel_time[pos - 1]] += CHSV( hue, 255, 255 - map(second(local), 0, 59, 0, 255) );
- leds[ map_pixel_time[pos]] += CHSV( hue, 255, 255 );
- leds[ map_pixel_time[pos + 1]] += CHSV( hue, 255, map(second(local), 0, 59, 0, 255) );
- }
- void draw_hour(int pos, uint8_t hue) {
- leds[ map_pixel_time[pos - 1]] += CHSV( hue, 255, 255 - map(minute(local), 0, 59, 0, 255) );
- leds[ map_pixel_time[pos]] += CHSV( hue, 255, 255 );
- leds[ map_pixel_time[pos+1]] += CHSV( hue, 255, 255 );
- leds[ map_pixel_time[pos + 2]] += CHSV( hue, 255, map(minute(local), 0, 59, 0, 255) );
- }
- void display_date_temp() {
- lcd.setCursor(3, 0);
- if ( day() < 10 ) { lcd.print("0"); }
- lcd.print(day());
- lcd.print(".");
- if ( month() < 10 ) { lcd.print("0"); }
- lcd.print(month());
- lcd.print(".");
- lcd.print(year());
- lcd.setCursor(0, 1);
- lcd.print(RTC.temperature() / 4.);
- lcd.print("\337C ");
- if ( hour(local) < 10 ) { lcd.print("0"); }
- lcd.print(hour(local));
- lcd.print(":");
- if ( minute(local) < 10 ) { lcd.print("0"); }
- lcd.print(minute(local));
- lcd.print(":");
- if ( second(local) < 10 ) { lcd.print("0"); }
- lcd.print(second(local));
- lcd.display();
- }
- void loop() {
- float pos_min_for_hour = floor(minute(local)/12);
- int pos_hour = (hour(local) % 12) * 5 + pos_min_for_hour;
- FastLED.clear();
- local = CE.toLocal(now(), &tcr);
- float gradient = minute(local)*99/59 + (hour(local)%3)*100;
- uint8_t second_hue = map( gradient, 0, 299, 0, 255);
- uint8_t minute_hue = second_hue + 35;
- uint8_t hour_hue = minute_hue + 35;
- if (second(local) != last_second) {
- mill = 0;
- last_time = millis();
- last_second = second(local);
- } else {
- mill = map( (millis() - last_time) % 1000, 0, 1000, 0, 255);
- }
- draw_hour(pos_hour+10, hour_hue);
- draw_minute(minute(local)+10, minute_hue);
- draw_second(second(local)+10, second_hue);
- if ( (hour(local) >= 1) & (hour(local) <= 4) ) {
- analogWrite(11, 0);
- FastLED.setBrightness(0); // energy saver
- FastLED.show();
- } else {
- analogWrite(11, 96);
- int led_brightness = 255 * ( 1 - exp(- analogRead(LDRPin)/800. * 5.));
- if (led_brightness < 20) { led_brightness = 20; }
- FastLED.setBrightness(led_brightness);
- FastLED.show();
- }
- display_date_temp();
- }
Advertisement
Add Comment
Please, Sign In to add comment