Guest User

Untitled

a guest
Sep 7th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <FastLED.h>
  2. #include <Wire.h>
  3. #include <RTClib.h>
  4. RTC_DS1307 RTC; // Establishes the chipset of the Real Time Clock
  5. #define LEDStripPin 6 // Pin used for the data to the LED strip
  6. #define menuPin A3 // Pin used for the menu button (green stripe)
  7. #define numLEDs 60 // Number of LEDs in strip
  8. struct CRGB leds[numLEDs];
  9. int LEDOffset = 30;
  10. void setup()
  11. {
  12. // Start LEDs
  13. FastLED.addLeds<NEOPIXEL, LEDStripPin>(leds, numLEDs);
  14. Wire.begin();
  15. RTC.begin();
  16. Serial.begin(9600);
  17. DateTime now = RTC.now();
  18.  
  19. Serial.print("Hour time is... ");
  20. Serial.println(now.hour());
  21. Serial.print("Min time is... ");
  22. Serial.println(now.minute());
  23. Serial.print("Sec time is... ");
  24. Serial.println(now.second());
  25.  
  26. Serial.print("Year is... ");
  27. Serial.println(now.year());
  28. Serial.print("Month is... ");
  29. Serial.println(now.month());
  30. Serial.print("Day is... ");
  31. Serial.println(now.day());
  32. }
  33.  
  34. void loop()
  35. {
  36. DateTime now = RTC.now();
  37. memset(leds, 0, numLEDs * 3);
  38. basicClock(now);
  39. LEDS.show();
  40. }
  41. void clearLEDs()
  42. {
  43. for (int i = 0; i < numLEDs; i++) // Set all the LEDs to off
  44. {
  45. leds[i].r = 0;
  46. leds[i].g = 0;
  47. leds[i].b = 0;
  48. }
  49. }
  50. void basicClock(DateTime now)
  51. {
  52. unsigned char hourPos = ((now.hour()%12)*5 + (now.minute()+6)/12);
  53. leds[(hourPos+LEDOffset+59)%60] = CRGB::Red;
  54. leds[(hourPos+LEDOffset)%60] = CRGB::Red;
  55. leds[(hourPos+LEDOffset+1)%60] = CRGB::Red;
  56. leds[(now.minute()+LEDOffset)%60] = CRGB::White;
  57. leds[(now.second()+LEDOffset)%60] = CRGB::Blue;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment