Can someone take a look at my clock code and seewhere I am going wrong?

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);

Thanks for any help offered.

I think there's something up with your equation:

hourval = (hourval*60 + minuteval) / 12;

You've got 12 hour LEDs but this expression exceeds that. For example, if hourval = 11 and minuteval = 59:

(11*60+59)/12 = 59.92

Maybe you want to Serial.print() some of your numbers to see if they're out of bounds.

Why not use one ring? second white, minute blue, hour red, minute on hour green

Then move hour hand every 12 minutes.

try replacing

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);

hope that helps.

Thanks for pointing that out Blackfin. I changed that line to read:

hourval = hourval % 12;

So if the hourval exceeds 12 then it would convert it. For example, if the hour retrieved from the RTC is 13 then it would convert the hourval to 1.

Unfortunately it still is not lightling up any pixels on the 12 pixel ring.

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.

This has got me stumped!

Can you try using a different color for the hour, such as:

stripH.setPixelColor(hourval, 0x00ffff);

Try a simple test with your code.
Add line stripH.setPixelColor(5, 0xff0000);

Does the pixel come on?

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... :stuck_out_tongue_winking_eye:

did you also try the new code line I posted?

hourval = ((hourval%12)*5) +(minuteval/12);

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.

If you tried stripH.setPixelColor(5, 0xff0000);
Your hardware or wiring may be bad.

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?

Have you Serial.print'd your hours, minutes and seconds to see if the hours number makes sense?

Blackfin, I looked at the hours and minutes in the serial monitor and it looks ok to me.

sherzaad, I am pulling the time from the RTC module and it is showing me in the serial monitor.

I'll create an image to show the wiring and upload it tomorrow.

Here is a rough layout of the wiring of the 2 rings and the RTC.

clcok-schem.jpg

Op's attached image:
clcok-schem.jpg

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;"

The strandtest you ran: Was it using the same data pin as your clock code does?