Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RGB LED Strip Setup
- #define NUM_LEDS_Sec 6 // Number of leds on DATA_PIN_Sec
- #define NUM_LEDS_Min 6 // Number of leds on DATA_PIN_Min
- #define NUM_LEDS_Hrs 5 // Number of leds on DATA_PIN_Hrs
- #define DATA_PIN_Sec 9 // The Data line for NUM_LEDS_Sec
- #define DATA_PIN_Min 8 // The Data line for NUM_LEDS_Min
- #define DATA_PIN_Hrs 7 // The Data line for NUM_LEDS_Hrs
- // Setup For FastLED.h
- #include <FastLED.h> // FastLED.h libary for rgb strip leds
- CRGB SecLedStrip[NUM_LEDS_Sec];
- CRGB MinLedStrip[NUM_LEDS_Min];
- CRGB HrsLedStrip[NUM_LEDS_Hrs];
- // Clock
- uint8_t hrs;
- uint8_t mins;
- uint8_t secs;
- // Initialize Buttons Used To Advance The Time
- int minButtonPin = 10;
- int hrsButtonPin = 11;
- int minButtonState = 0;
- int hrsButtonState = 0;
- void setup()
- {
- // Initialize LED Strips
- FastLED.addLeds<NEOPIXEL, DATA_PIN_Sec>(SecLedStrip, NUM_LEDS_Sec);
- FastLED.addLeds<NEOPIXEL, DATA_PIN_Min>(MinLedStrip, NUM_LEDS_Min);
- FastLED.addLeds<NEOPIXEL, DATA_PIN_Hrs>(HrsLedStrip, NUM_LEDS_Hrs);
- // Set ButtonPins To Input And Pull Up
- pinMode(minButtonPin, INPUT_PULLUP);
- pinMode(hrsButtonPin, INPUT_PULLUP);
- }
- void loop()
- {
- static uint32_t tick_tm = millis(); // 1 Second Tick Mark
- // Buttons To Advance The Time - Hours Or Minutes
- hrsButtonState = digitalRead(hrsButtonPin);
- minButtonState = digitalRead(minButtonPin);
- if (minButtonState == LOW){
- mins++;
- delay(250);
- }
- if (hrsButtonState == LOW){
- hrs++;
- delay(250);
- }
- // One Second Tick
- if (millis() - tick_tm > 1000UL){
- tick_tm += 1000UL; // Advance by Exactly 1 Second For Precision Timekeeping
- // Increment The Time
- secs++;
- if (secs > 59) { secs = 0; mins++; }
- if (mins > 59) { mins = 0; hrs++; }
- if (hrs > 23) hrs = 0; // Simple Wrap Clock
- }
- // Constantly Update The Display
- updateLedStrip( SecLedStrip, secs, NUM_LEDS_Sec, CRGB::Blue );
- updateLedStrip( MinLedStrip, mins, NUM_LEDS_Min, CRGB::Green );
- updateLedStrip( HrsLedStrip, hrs, NUM_LEDS_Hrs, CRGB::Red );
- FastLED.show();
- }
- // Update One LED Strip
- void updateLedStrip( struct CRGB *led_strip, uint8_t val, uint8_t num_leds, CRGB::HTMLColorCode color )
- {
- for (uint8_t i=0; i < num_leds; i++)
- // One Bit Per LED In The Strip
- led_strip[i] = (val & (1 << i)) ? color : CRGB::Black;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement