Need a little help understanding.

I'm needing some help with this project. I was looking around on Instructables and found this clock project. I thought I would be able to figure it out, but I think I'm in over my head. The instructable provides everything you need, but I wanted to change it up some. I bought an Arduino starter kit to try and understand how it works. I'm hoping someone is willing you help me out with this. Here is a link to everything I've done. I uploaded the code that I've been trying to modify and a zipped copy of the original file. When I plug the clock in it comes on, but only a few LED light up. The hour button and minutes button makes changes. It also dims when I turn out the lights.

Welcome to the Forum. Most forum members are not interested in downloading code from links. You should post your code. First, please read the two posts

How to use this forum - please read.
and
Read this before posting a programming question ...

Code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.

Many questions can be answered by simply reading the documentation which is provided with the IDE, available under the help tab, or online here.

There are many other things that programmers do to make their code understandable. Please do them, as a courtesy to the members who volunteer their time to help you here. One is to use a standard indentation to clearly show the code blocks. Never put more than one statement per line. Place any brackets by themselves on a separate line. Before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read. Another is to give things descriptive names. You can name numerical constants, pin numbers, variables and many other things in this way. For example, you can refer to a pin and an output level by number, like digitalWrite(3,0). But such a statement doesn't reveal anything about the purpose. digitalWrite(hornRelayPin, LOW) does. You can do that by declaring const byte hornRelayPin = 3; before setup() in your program. Many such names are already defined for you by the compiler and the Arduino IDE. Here are some:

#define HIGH 0x1
#define LOW  0x0
#define PI 3.1415926535897932384626433832795

Use them. There are many more. Use compiler math to compute values so you can see where they came from (or at least document them). For example, if you see the number 73, you would be hard put to explain the significance of it. But if you see "daysPerYear/5", it is obvious. One more thing. When you work on program continuously, you become familiar with it. So many things seem obvious even if they are not spelled out explicitly. But try looking at your own code six months later. It will be as if a stranger wrote it. So write for strangers, not yourself.

cjlamb:
The instructable provides everything you need, but I wanted to change it up some.

Which is the original instructable?
Which are the changes (hardware? software? list of all changes?) you did?

As far as I know most WS2811/WS2812 LED strips are powered by 5V only and can be cut after each single LED. I'm wondering why you are showing a wiring.jpg picture which tells something about 12V.

Which LED strip do you use? Which power adapter?

Do you have a schematics of the complete circuit you designed?

Can you post a link to the original project (instructable)? How do you power the LEDs (and the rest of the circuit)? It looks to me that you need quite a powerful power supply.

Here is the link to the clock. Instructables

The lights he used required 12v and the light I used only require 5v. I had already order a 12v wall wart so I used it. His is a 24 hour clock and I'm wanting mine to be a 12 hour clock.

cjlamb:
The lights he used required 12v and the light I used only require 5v.

OK, so the original LED strip is 12V ==> 1 WS2811 IC controls 3 LEDs at once
(always 3 consecutive LEDs in the strip will show the same color and intensity)

And your LED strip is 5V ==> each single LED is controlled by its own WS2811 IC
(each single LED in the strip can have its own color and intensity)

So you have to adapt the number of LEDs you control.
With the original hardware you control 3 LEDs at once when controlling one WS2811 "pixel".
With your hardware you control just 1 LED with one WS2811 pixel.
Your code has to take that into account in its programming logic.

cjlamb:
I had already order a 12v wall wart so I used it.

That is completely wrong: Most likely you powered 12V into the Arduino board and then try to draw all the LED current from the 5V pin of the Arduino board?

The voltage controller on the Arduino board might EXPLODE or BURN OUT when doing so!
Kids, don't try this at home!

When powering more than perhaps 10 WS2811/WS2812 LEDs in a 5V LED strip, you will need to have 5V power adapter which can provide enough current to drive the LEDs.

Each R, G, and B of those LEDs can use up to 20mA when controlled to highest brightness, that is up to 60mA per LED.

How many LEDs do you want to control in your circuit?
23 segments of 5 LEDs each = 23*5 = 115 LEDs?

115 LEDs at full brightness of 0.06A = 115*0.06A = 6.9 Ampere

So you need a power adapter which can provide 5V/7Amp at least, if you want to drive all LEDs with full power.

Maybe a 5V/5Amp adapter is enough when driving not all LEDs at the same time or with reduced brightness.

Go and get one!

What about a safety resistor in the data line between Arduino board and the first LED, do you have one?
If not, go and get one and put it in the circuit!

When the hardware is ready, start programming!

jurs:
When the hardware is ready, start programming!

I am trying to program it. I have a buck converter set to 5.5 volts that's how I'm powering the led's. I must be missing something because the clock is acting weird. Here is what I've done so far.

#include <DS3232RTC.h>
#include <Time.h>
#include <Wire.h>
#include "FastLED.h"
#define NUM_LEDS 117 // Number of LED controles (remember I have 3 leds / controler
#define COLOR_ORDER BRG // Define color order for your strip
#define DATA_PIN 6 // Data pin for led comunication

CRGB leds[NUM_LEDS]; // Define LEDs strip
byte digits[11][35] = {{0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 0
{0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1}, // Digit 1
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0}, // Digit 2
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1}, // Digit 3
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1}, // Digit 4
{1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1}, // Digit 5
{1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 6
{0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1}, // Digit 7
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}, // Digit 8
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1}}; // Digit 9 | 2D Array for numbers on 7 segment
bool Dot = true; //Dot state
bool DST = false; //DST state
int ledColor = 0x0000FF; // Color used (in hex)
void setup(){
// Serial.begin(9600);
// Wire.begin();
LEDS.addLeds<WS2811, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Set LED strip type
LEDS.setBrightness(255); // Set initial brightness
pinMode(2, INPUT_PULLUP); // Define DST adjust button pin
pinMode(4, INPUT_PULLUP); // Define Minutes adjust button pin
pinMode(5, INPUT_PULLUP); // Define Hours adjust button pin
}
// Get time in a single number, if hours will be a single digit then time will be displayed 155 instead of 0155
int GetTime(){
tmElements_t Now;
RTC.read(Now);
//time_t Now = RTC.Now();// Getting the current Time and storing it into a DateTime object
int hour=Now.Hour;
int minutes=Now.Minute;
int second =Now.Second;
if (second % 2==0) {Dot = false;}
else {Dot = true;};
return (hour*100+minutes);
};

// Check Light sensor and set brightness accordingly
void BrightnessCheck(){
const byte sensorPin = 3; // light sensor pin
const byte brightnessLow = 5; // Low brightness value
const byte brightnessHigh = 255; // High brightness value
int sensorValue = digitalRead(sensorPin); // Read sensor
if (sensorValue == 0) {LEDS.setBrightness(brightnessHigh);}
else {LEDS.setBrightness(brightnessLow);}
};

// Convert time to array needet for display
void TimeToArray(){
int Now = GetTime(); // Get time
int cursor = 117;

// Serial.print("Time is: ");Serial.println(Now);
if (DST){ // if DST is true then add one hour
Now+=100;
// Serial.print("DST is ON, time set to : ");Serial.println(Now);
};
if (Dot){leds[46,47]=ledColor;}
else {leds[46,47]=0x000000;
};
for(int i=1;i<=4;i++){
int digit = Now % 10; // get last digit in time
if (i==1){
// Serial.print("Digit 4 is : ");Serial.print(digit);Serial.print(" ");
cursor =22;
for(int k=0; k<=6;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
else if (i==2){
// Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" ");
cursor -=14;
for(int k=0; k<=6;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
else if (i==3){
// Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" ");
cursor =7;
for(int k=0; k<=6;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
else if (i==4){
// Serial.print("Digit1 is : ");Serial.print(digit);Serial.print(" ");
cursor =0;
for(int k=0; k<=6;k++){
// Serial.print(digits[digit][k]);
if (digits[digit][k]== 1){leds[cursor]=ledColor;}
else if (digits[digit][k]==0){leds[cursor]=0x000000;};
cursor ++;
};
// Serial.println();
}
Now /= 10;
};
};
void DSTcheck(){
int buttonDST = digitalRead(2);
// Serial.print("DST is: ");Serial.println(DST);
if (buttonDST == LOW){
if (DST){
DST=false;
// Serial.print("Switching DST to: ");Serial.println(DST);
}
else if (!DST){
DST=true;
// Serial.print("Switching DST to: ");Serial.println(DST);
};
delay(500);
};
}

void TimeAdjust(){
int buttonH = digitalRead(5);
int buttonM = digitalRead(4);
if (buttonH == LOW || buttonM == LOW){
delay(500);
tmElements_t Now;
RTC.read(Now);
int hour=Now.Hour;
int minutes=Now.Minute;
int second =Now.Second;
if (buttonH == LOW){
if (Now.Hour== 12){Now.Hour=0;}
else {Now.Hour += 1;};
}else {
if (Now.Minute== 59){Now.Minute=0;}
else {Now.Minute += 1;};
};
RTC.write(Now);
}
}
void loop() // Main loop
{
BrightnessCheck(); // Check brightness
DSTcheck(); // Check DST
TimeAdjust(); // Check to se if time is geting modified
TimeToArray(); // Get leds array with required configuration
FastLED.show(); // Display leds array
}

cjlamb:
I am trying to program it. I have a buck converter set to 5.5 volts that's how I'm powering the led's.

Stable power? Good for how many amperes?

cjlamb:
I must be missing something because the clock is acting weird.

The clock is most likely doing exactly what your program tells to do.

The original code is for controlling
4 digits of 7 segments each consisting of 1 pixel (3 LEDs controlled by one WS2811
plus additional 1 pixel (3 LEDs) for the double period in the middle (one LED hidden by duct tape)

But you need instead a code for controlling

  • 1 digit with 2 segments each consisting of 5 pixels (1 LED controlled by one WS2811)
  • 3 digits with 7 segments each consisting of 5 pixels (1 LED controlled by one WS2811)
    plus additional 2 pixels (2 LEDs) for the double period in the middle.

That requires a completely different programming logic than that used with the LED stripe in the original project.

So I'd think about creating a completely different program.

And as a starting point I'd not try to show all digits at once, but at first I'd create a test sketch that can show each digit at the correct position of its own:

  • first digit: nothing or 1
  • second, third, forth digit: 0 to 9

If every single digit can be displayed where it should appear, then try to create 3 or 4 digits containing the time as the next step.

jurs:
Stable power? Good for how many amperes?

Well I really don't know what the hell I'm doing. I guess I should make it just like his. I thought I'd be able to figure it out. As far as knowing how many amperes it's good for I have know idea. When I seen the clock I just jump head first into this thinking I could make it work. I don't even understand how to create a test sketch. I'm not going to give up just yet. Thanks for your help

cjlamb:
Well I really don't know what the hell I'm doing. I guess I should make it just like his. I thought I'd be able to figure it out. As far as knowing how many amperes it's good for I have know idea. When I seen the clock I just jump head first into this thinking I could make it work. I don't even understand how to create a test sketch. I'm not going to give up just yet. Thanks for your help

Don't give up... the hardware was the hard part.

If you can provide, for each digit, all of the LEDs (by their number; Zero being the one closest to the arduino) that comprise each digit... we can give you a test sketch that does what you want to do, quite easily.

byte singleMinutes[10][MOST_LEDS] = {
  {98,97,96,95,94,93},   // zero
  {45,46,47,48,64,65,66,55,54,53,52}, // one
  {... etc
};

where MOST_LEDS is the total number of LEDs in the digit eight.

also do one array for each digit:

byte tensMinutes[10][MOST_LEDS] = {
...
...
};

byte singleHours[10][MOST_LEDS] = {
...
...
};

byte tensHours[LEDS_IN_A_ONE] = {1, 2,3,4,5,6,7,8}; //for example

that will give us buckets of LEDs to lite when we start down this road.

have at it and report back. Note that many of these buckets will share led numbers.

If you just do the first digit, we can help you generate the code to lite them.

BulldogLowell:
Don't give up... the hardware was the hard part.

Right now I'm trying to get the RTC module to keep time. It's working, but it's almost like I'm holding down the DST button.
Picture of time

  #include <DS3232RTC.h>
  #include <Time.h> 
  #include <Wire.h>

  bool Dot = true;  //Dot state
  bool DST = false; //DST state

  void setup(){ 
    Serial.begin(9600); 
    Wire.begin(); 
  } 
  
  // Check Light sensor and set brightness accordingly
  void BrightnessCheck(){
  const byte sensorPin = 3; // light sensor pin
  const byte brightnessLow = 5; // Low brightness value
  const byte brightnessHigh = 255; // High brightness value
  int sensorValue = digitalRead(sensorPin); // Read sensor
  if (sensorValue == 0) {Serial.println("Brightness High");}
  else {Serial.println("Brightness Low");}  
  };
  // Get time in a single number
  int GetTime(){
    tmElements_t Now;
    RTC.read(Now);
    int hour=Now.Hour;
    int minutes=Now.Minute;
    if (hour>12 ){hour -= 12;}
    return (hour*100+minutes);
    };
    
  void DSTcheck(){
   int buttonDST = digitalRead(2);
   Serial.print("DST is: ");Serial.println(DST);
   if (buttonDST == LOW){
    if (DST){
      DST=false;
      Serial.print("Switching DST to: ");Serial.println(DST);
      }
      else if (!DST){
        DST=true;
        Serial.print("Switching DST to: ");Serial.println(DST);
      };
   delay(500);   
   };
  }   
  // Convert time to array needet for display 
  void TimeToArray(){
    int Now = GetTime();  // Get time  
    Serial.print("Time is: ");Serial.println(Now);
    for(int i=1;i<=4;i++){
    int digit = Now % 10; // get last digit in time
    if (i==1){
        Serial.print("Digit 4 is : ");Serial.print(digit);Serial.print(" ");
        Serial.println();
      }
    else if (i==2){
        Serial.print("Digit 3 is : ");Serial.print(digit);Serial.print(" ");
        Serial.println();
      }
    else if (i==3){
        Serial.print("Digit 2 is : ");Serial.print(digit);Serial.print(" ");
        Serial.println();
      }
    else if (i==4){
        Serial.print("Digit 1 is : ");Serial.print(digit);Serial.print(" ");
  //      Serial.println();
      }
    Now /= 10;
    }; 
  };
  
void TimeAdjust(){
  int buttonH = digitalRead(5);
  int buttonM = digitalRead(4);
  if (buttonH == LOW || buttonM == LOW){
    delay(500);
    tmElements_t Now;
    RTC.read(Now);
    int hour=Now.Hour;
    int minutes=Now.Minute;
      if (buttonH == LOW){
        if (Now.Hour== 24){Now.Hour=1;}
          else {Now.Hour += 1;};
        }else {
          if (Now.Minute== 59){Now.Minute=0;}
          else {Now.Minute += 1;};
          };
    RTC.write(Now); 
    }
  }
  void loop()  // Main loop
  { 
    BrightnessCheck(); // Check brightness
    DSTcheck(); // Check DST
    TimeAdjust(); // Check to se if time is geting modified
    TimeToArray(); // Get leds array with required configuration
  }

you have to set the pin to INPUT

  void setup(){ 
    Serial.begin(9600); 
    pinMode(2, INPUT); // or INPUT_PULLUP if you are not using an external pull-up resistor on the button.
    Wire.begin(); 
  }

BulldogLowell:
you have to set the pin to INPUT

  void setup(){ 

Serial.begin(9600);
    pinMode(2, INPUT); // or INPUT_PULLUP if you are not using an external pull-up resistor on the button.
    Wire.begin();
  }

What size pull-up resistor do I need?

You don't need and external pull up resistor if you use the internal pull up resistor. Just modify the code to say input pull up as I demonstrated

BulldogLowell:
You don't need and external pull up resistor if you use the internal pull up resistor. Just modify the code to say input pull up as I demonstrated

You the man. Thanks I add this and it fixed my problems. Now time for the led's

void setup(){ 
    Serial.begin(9600); 
    Wire.begin();
  pinMode(2, INPUT_PULLUP); // Define DST adjust button pin
  pinMode(4, INPUT_PULLUP); // Define Minutes adjust button pin
  pinMode(5, INPUT_PULLUP); // Define Hours adjust button pin 
  }