Skip to content

Instantly share code, notes, and snippets.

@kevinmarx
Created February 19, 2015 15:03
Show Gist options
  • Save kevinmarx/1a0ec9cc9b88a6e778bc to your computer and use it in GitHub Desktop.
Save kevinmarx/1a0ec9cc9b88a6e778bc to your computer and use it in GitHub Desktop.
Color Clock for Arduino
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_NeoPixel.h>
#define PIN 5
#define NUMPIXELS 8
RTC_Millis rtc;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int second;
DateTime now;
void setup() {
pixels.begin();
rtc.begin(DateTime(F(__DATE__), F(__TIME__)));
}
void loop() {
now = rtc.now();
if (second != now.second()) {
second = now.second();
updateLED();
}
}
void updateLED() {
now = rtc.now();
float red = ((float) now.hour() / 24) * 255;
float green = ((float) now.minute() / 60) * 255;
float blue = ((float) now.second() / 60) * 255;
Bean.setLed(red, green, blue);
for (int i=0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(red, green, blue));
pixels.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment