I am new at this but I am trying to make a clock using 2 NeoPixel rings. The minutes and seconds should display on the 60 pixel Ring and the hours should display on the 12 pixel ring. I have put together some code but it is not working as I hoped it would.
The minutes and seconds are working properly on the 60 pixel ring but the hours are not being displayed on the 12 pixel ring. In fact, the 12 pixel ring does not have any pixels lit up. I know the ring is ok because I ran the strandtest from the Adafruit_NeoPixel library and all the pixels lit up fine. It is obviously something in the code. Can anyone take a look at this code and tell me where I am going wrong?
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_NeoPixel.h>
#define PIN 10
#define PIXEL 60
#define PINH 6
#define PIXELH 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800); // strip for minutes & seconds.
Adafruit_NeoPixel stripH = Adafruit_NeoPixel(PIXELH, PINH, NEO_GRB + NEO_KHZ800); // strip for hours
RTC_DS1307 RTC; // Establish clock object
DateTime Clock; // Holds current clock time
byte hourval, minuteval, secondval;
void setup() {
Serial.begin(9600);
Wire.begin(); // Begin I2C
RTC.begin(); // begin clock
strip.begin();
stripH.begin();
strip.show(); // Initialize all pixels to 'off'
stripH.show();
strip.setBrightness(20);
stripH.setBrightness(20);
}
void loop() {
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
hourval = (hourval*60 + minuteval) / 12;
stripH.setPixelColor(hourval, 0xff0000);
strip.setPixelColor(minuteval, 0x008000);
strip.setPixelColor(secondval, 0x0000ff);
strip.show();
stripH.show();
stripH.setPixelColor(hourval, 0x000000);
strip.setPixelColor(minuteval, 0x000000);
strip.setPixelColor(secondval, 0x000000);
delay(25);
if(hourval > 11) hourval -= 12; // This clock is 12 hour, if 13-23, convert to 0-11
hourval = (hourval*60 + minuteval) / 12;
with
hourval = hourval%12; // This clock is 12 hour, if 13-23, convert to 0-11
hourval = (hourval*5) +(minuteval/12);
//OR AS IN A SINGLE LINE
hourval = ((hourval%12)*5) +(minuteval/12);
I have not problem getting the clock to work using only one ring but I really want to use the2 rings for my design. I will also be utilizing 7 separate leds to indicate the day of the week in this design but thanks for your suggestion.
Thanks sherzaad. I did replace that line and added the +1 as you suggested but it still does not display anything on the 12 pixel ring. I checked and rechecked the wiring to the Arduino Uno and it looks fine.
ve3joc:
Thanks sherzaad. I did replace that line and added the +1 as you suggested but it still does not display anything on the 12 pixel ring. I checked and rechecked the wiring to the Arduino Uno and it looks fine.
This has got me stumped!
sorry I changed my first post a couple of times while you guys were replying...
ve3joc:
Thanks for your patience guys. I tried Blackfins color change, I tried Larryd's color chamge and I added sherzaad's line of code and still nothing.
maybe a silly question but how are do you know what time your clock is supposed to be showing?
did you try controlling the rings seperately? ie with your current hardware set up do you have a sketch to control your 12 ring only AND another sketch to control the 60 ring?
did the 12 ring work then?
also I originally thought you were using a 60 ring to display your 'hour'. since its a 12 ring this would be the code to calculate the value to display to the 12 ring: "hourval = hourval%12;"