NeoPixel 60 Ring Wall Clock

advertisement
NeoPixel 60 Ring Wall Clock
Created by Andy Doro
Last updated on 2016-09-22 07:45:48 PM UTC
Guide Contents
Guide Contents
Overview
Building the Circuit
Code
Finishing it up
© Adafruit Industries
2
3
5
7
11
https://learn.adafruit.com/neopixel-60-ring-clock
Page 2 of 11
Overview
This project uses the DS1307 Real Time Clock (http://adafru.it/264) with an Arduino to
display the time as a series of colored arcs.
With the new NeoPixel 60 Ring (http://adafru.it/1768), we have a perfect display for
presenting the time with RGB LEDs!
Hours are represented by red, minutes by green, seconds by blue. The arcs overlap and
the colors mix. Minutes and seconds are each represented by a single green or blue LED,
respectively. In the 12 hour version, a single red LED represent 24 minutes. The image
above represents 3:48.
To build this project you will need:
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 3 of 11
4 x NeoPixel 1/4 60 Ring (http://adafru.it/1768) - so you can make a NeoPixel 60 Ring
DS1307 Real Time Clock breakout board kit (http://adafru.it/264)
Arduino Uno (http://adafru.it/50) or other Arduino compatible microcontroller. This will
even work with the Trinket 5V (http://adafru.it/1501)!
Adafruit Perma-Proto Half-sized Breadboard PCB (http://adafru.it/1609)
If you are new to microcontrollers and Arduino, I would recommend starting out by building
the circuit using the Arduino Uno (http://adafru.it/50) and a breadboard (http://adafru.it/239).
If you are more familiar with Arduino, you can use aTrinket 5V (http://adafru.it/1501) and
perfboard to build a more permanent electronics project.
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 4 of 11
Building the Circuit
Solder 4 pieces of the the NeoPixel 1/4 60 Ring together, connecting GND to GND, 5V to
5V and DIN to DOUT. Butt the ends together and use a small piece of stripped wire as a
'bridge' to give some mechanical support
Leave one pair of DIN and DOUT disconnected- this will be where the NeoPixel strand
begins and ends.
The ring is very delicate! So please mount onto a backing or use care when moving
around!
Note that the diagram above depicts a NeoPixel Ring with 24 NeoPixels, but the same
principal applies!
NeoPixel Ring connects as follows:
+5V → 5V on Arduino or USB on Trinket (red wire)
GND → GND on Arduino (black wire)
DIN → Digital 3 on Arduino (blue wire)
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 5 of 11
DS1307 connects as follows:
+5V → 5V on Arduino (red wire)
GND → GND on Arduino (black wire)
SDA → Analog 4 on Arduino or #0 on Trinket (green wire)
SCL → Analog 5 on Arduino or #2 on Trinket (orange wire)
Assemble the DS1307 breakout following these instructions (http://adafru.it/ixe).
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 6 of 11
Code
Important note: when running this code, you should probably use an external power supply
(say 9VDC into the Arduino). When I ran the code on USB power, the NeoPixels drew too
much current and this caused the RTC to provide strange numbers to the Arduino.
Download the code (http://adafru.it/fFC) and uncompress in your Arduino sketch folder.
This Arduino sketch relies on a few Arduino libraries:
RTClib (http://adafru.it/c7r)
Adafruit_NeoPixel (http://adafru.it/aZU)
Follow the DS1307 RTC breakout tutorial (http://adafru.it/dhu) to learn how to install the
RTC library and set the time on the DS1307 RTC.
You will also need to install the NeoPixel library (http://adafru.it/dhv). See the following
tutorial to learn how to install Arduino libraries (http://adafru.it/dit).
/**************************************************************************
*
*
* NeoPixel Ring Clock
*
* by Andy Doro (mail@andydoro.com)
*
* http://andydoro.com/ringclock/
*
*
*
**************************************************************************
*
*
* Revision History
*
* Date By What
* 20140320 AFD First draft
* 20160105 AFD Faded arcs
* 20160916 AFD Trinket compatible
*/
// include the library code:
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_NeoPixel.h>
// define pins
#define NEOPIN 3
#define BRIGHTNESS 64 // set max brightness 0-255
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 7 of 11
RTC_DS1307 RTC; // Establish clock object
DateTime Clock; // Holds current clock time
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, NEOPIN, NEO_GRB + NEO_KHZ800); // strip object
byte hourval, minuteval, secondval; // holds the time
byte pixelColorRed, pixelColorGreen, pixelColorBlue; // holds color values
void setup () {
Wire.begin();
// Begin I2C
RTC.begin(); // begin clock
//Serial.begin(9600);
// set pinmodes
pinMode(NEOPIN, OUTPUT);
if (! RTC.isrunning()) {
// Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
strip.begin();
//strip.show(); // Initialize all pixels to 'off'
strip.setBrightness(BRIGHTNESS); // set brightness
// startup sequence
delay(500);
colorWipe(strip.Color(255, 0, 0), 20); // Red
colorWipe(strip.Color(0, 255, 0), 20); // Green
colorWipe(strip.Color(0, 0, 255), 20); // Blue
delay(500);
}
void loop () {
char* colon = ":"; // static characters save a bit
char* slash = "/"; // of memory
// get time
Clock = RTC.now(); // get the RTC time
secondval = Clock.second(); // get seconds
minuteval = Clock.minute(); // get minutes
hourval = Clock.hour(); // get hours
if (hourval > 11) hourval -= 12; // This clock is 12 hour, if 13-23, convert to 0-11
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 8 of 11
hourval = (hourval * 60 + minuteval) / 12; //each red dot represent 24 minutes.
// arc mode
for (uint8_t i = 0; i < strip.numPixels(); i++) {
if (i <= secondval) {
// calculates a faded arc from low to maximum brightness
pixelColorBlue = (i + 1) * (255 / (secondval + 1));
//pixelColorBlue = 255;
}
else {
pixelColorBlue = 0;
}
if (i <= minuteval) {
pixelColorGreen = (i + 1) * (255 / (minuteval + 1));
//pixelColorGreen = 255;
}
else {
pixelColorGreen = 0;
}
if (i <= hourval) {
pixelColorRed = (i + 1) * (255 / (hourval + 1));
//pixelColorRed = 255;
}
else {
pixelColorRed = 0;
}
strip.setPixelColor(i, strip.Color(pixelColorRed, pixelColorGreen, pixelColorBlue));
}
/*
// for serial debugging
Serial.print(hourval, DEC);
Serial.print(':');
Serial.print(minuteval, DEC);
Serial.print(':');
Serial.println(secondval, DEC);
*/
//display
strip.show();
// wait
delay(100);
}
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 9 of 11
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for (uint16_t i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
You can edit the #define BRIGHTNESS value to change the maximum brightness. This
value can be from 0-255 although with 0 you won't be able to see anything.
© Adafruit Industries
https://learn.adafruit.com/neopixel-60-ring-clock
Page 10 of 11
Finishing it up
You might want to put a heatsink on the voltage regulator- the NeoPixels use a lot of
current, causing the voltage regulator to get hot!
I used a spare circular piece of black plexi to hide the electronics behind, since I'm just
hanging the clock near a desk. If you want to you can create a more sophisticated
enclosure for this clock.
© Adafruit Industries
Last Updated: 2016-09-22 07:45:47 PM UTC
Page 11 of 11
Download