16 digit 7 segments digital clock

I got a code and try to developed by ai a code of 16 digit 7 SEGMENTS common anode clock when I run in proteous Arduino uno in 4mhz it's work like charm but in physically it stuck and all segments showing 88:88:88. can any one help to recover and reconstruct the sketch? though I'm know nothing about programming

#include "RTClib.h"

RTC_DS3231 rtc;

// Global display array (16 digits) used for normal and setting modes.
int my_str[16];
int tempC, d;

// Button pins (using internal pull-ups)
const int upPin   = 7;
const int downPin = 8;
const int okPin   = 9;
const int savePin = 10;

// Shift register pins for 7-seg patterns
int latchPin  = 12;
int clockPin  = 13;
int dataPin   = 11;

// Shift register pins for digit enable (16 outputs)
int latchPin2 = 5;
int clockPin2 = 6;
int dataPin2  = 4;

// Shift register pins for day-of-week indicator
int latchPin3 = A0;
int clockPin3 = A1;
int dataPin3  = A2;

int digit_code = 0;
int week_day = 0;

// New pins for AM/PM indicator and 7-seg decimal point (segDP)
const int ampmPin  = 2;    // Unused digital pin for AM/PM indicator
const int segDPPin = 3;    // Unused digital pin for controlling segDP

//---------------------------------------------------------------------
// Revised dayofweek() function:
// Assumes rtc.now().dayOfTheWeek() returns 0 for Sunday, 1 for Monday, …, 6 for Saturday.
// Returns a bit mask with bit0 for Sunday, bit1 for Monday, …, bit6 for Saturday.
int dayofweek (int y) {
  if (y < 0 || y > 6) return 0;
  return 1 << y;   // For example, if y==0, returns 1 (binary 00000001); if y==6, returns 64 (binary 01000000)
}

void getDate(char *psz)
// Date Setup: Code for reading clock date
{
   char  szBuf[10];
 
  
   dd=Clock.getDate();
   mm=Clock.getMonth(Century); //12
   yyy=Clock.getYear();
   sprintf(psz, "%d %s %04d",dd , mon2str(mm, szBuf, sizeof(szBuf)-1),(yyy + 2000));
 
}

void setup(void)
{
  P.begin(2);
  P.setInvert(false); //we don't want to invert anything so it is set to false
  Wire.begin();
  
  P.setZone(0,  MAX_DEVICES-4, MAX_DEVICES-1);
  
  P.setZone(1, MAX_DEVICES-4, MAX_DEVICES-1);
  P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);

  P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0,PA_PRINT , PA_NO_EFFECT);

  P.addChar('$', degC);
  P.addChar('&', degF);

}

void loop(void)
{
  static uint32_t lastTime = 0; // millis() memory
  static uint8_t  display = 0;  // current display mode
  static bool flasher = false;  // seconds passing flasher

  P.displayAnimate();

   if (P.getZoneStatus(0))
  {
    switch (display)
    {
      case 0:    // Temperature deg C
      P.setPause(0,1000);
      P.setTextEffect(0, PA_OPENING, PA_CLOSING);
      //P.setTextEffect(0, PA_MESH, PA_BLINDS);
      display++;    
      dtostrf(Clock.getTemperature(), 3, 1, szMesg);
      strcat(szMesg, "$");
      //strcat(szMesg, "26.5$");
    

        break;

      case 1: // Temperature deg F
        P.setTextEffect(0, PA_OPENING, PA_CLOSING);
        //P.setTextEffect(0, PA_OPENING, PA_GROW_DOWN);
        display++;
        dtostrf((1.8 *Clock.getTemperature() )+32, 3, 1, szMesg);
        strcat(szMesg, "&");
   
   
   // strcpy(szMesg, "71.6&");

        break;

      case 2: // Clock
     
     P.setFont(0, numeric7Seg);
     P.setTextEffect(0, PA_PRINT, PA_NO_EFFECT);
     //Sleep Mode
     //Uncomment to enable Sleep Mode and adjust the hours to your needs
     /*if (h==12 || h<8)//Time intervals (in this case, from 12AM to 8AM) 
     {
      P.setIntensity(0); //Set display brightness to lowest setting
     }
     else
     {
      P.setIntensity(3); //Set display brightness to 6 (15 is the brighest)
     }*/
     P.setPause(0,0);

     if (millis() - lastTime >= 1000)
    {
    lastTime = millis();
    getTime(szMesg, flasher);
    flasher = !flasher;
    }
    if(s==00&& s<=30){
    display++;
    P.setTextEffect(0, PA_PRINT, PA_SCROLL_UP);
    }

    //  strcpy(szMesg, "36 % RH");               
    
        break;
      
      case 3: // day of week
       
        P.setFont(0,nullptr);
        P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
        display++;
        dow2str(Clock.getDoW()+1, szMesg, MAX_MESG); // Added +1 to get correct DoW

       //dow2str(5, szMesg, MAX_MESG);
        break;
      default:  // Calendar
        
        P.setTextEffect(0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
        display = 0;
        getDate(szMesg);
        break;
    }

    P.displayReset(0);  
  }
'

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

It is also helpful to post error messages in code tags as it makes it easier to scroll through them and copy them for examination

Please confirm which Arduino board you are using

arduino uno

Then why did you post in the Zero board category of the forum

Exactly which Uno ?
R3 ?
R4 ?

uno r3

I have moved the topic to a more appropriate forum category. Please edit your first post and add code tags the code

Please also post a schematic of your project. A 'photo of a hand drawn circuit is good enough

I think a such AI generated nonsense can't be fixed at any way...

The code is a best example why you need a programming skills to use an AI to generate code.

Post an annotated schematic showing exactly how you have built this. Post links to technical information on all non generic parts. As far as the code it is just gibberish as you have posted it.

Show a screen shot of the schematic from Proteus.

It is likely that you will have to develop a much simpler sketch just to test your hardware build. Something like pushing out a byte at one second intervals to the shift register chain to see what appears across the display.

Your code could be optimised and generally tidied up, for example, by using for loops instead of copying and pasting large chunks of code but, anyway, first attempt to verify the hardware set up.

One common error is to use the wrong display type. These can be common anode or common cathode.

I can't give screenshot right now, I'm using common anode 16 digit 7 segment,

i'm upload detail of my project can you give me solution?

What is the part number of the chips which are driving the Led displays?
Proteus might be less sensitive to issues like
missing current limiting resistors, decoupling capacitors etc. than a real hardware build explaining your apparent success with the simulation.

simulation in proteous is fine but when I try on my bread board it's not work.. I use 74hc595 shift registers to control.. look at screenshot of proteous

The screenshot is too small to be useful. Unfortunately the way AI creates one big glob of code is not very useful if you need to debug or maintain it. You need to start small and build up.

If the breadboard is part of the circuit, provide a schematic for that.

I can't see the numbering on the shift registers but it does appear from your code and from what I can see of the schematic (it has poor resolution) that four shift registers are configured as 3 chains. That is 1 chain has two shift registers. The other two chains have only one shift register each. Maybe the AI agent you used has some explanation for this rather odd distribution. I'd have put all four shift registers in the same chain.

Anyway, you've told us that it works under Proteus so the chances are good that either you have made a wiring error, a device is faulty or, as said before, missing components are the problem.

For your troubleshooting start small. Just ask the AI agent to produced the minimal code necessary to light each of the "day of week" leds displaying it for one second, then the next. Test the code in Proteus then test it in your hardware build.

Hi, @hasim06
Welcome to the forum.

PLEASE do not keep editing your first post when asked to post things.
ALWAYS add extra information in new posts, at the moment this threat is becoming very confusing.

Please post an EXPORTED image of your schematic, not a screen capture.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

The lack of current limiting resistors is going to be turning on the LEDs very brightly for what seems like a very short duration due to the very rapid switching ON and OFF of each individual 7-segment display. That is a very odd method of multiplexing displays, almost the exact opposite of the usual method of leaving a digit on for a fairly long time, and then briefly turning off all displays while changing the pattern from one display to the next.

The multiplexing through the entire display needs to be done at a rate of around 50Hz or more so that persistence of vision eliminates the apparent blinking. With 16 7-segment displays, instead of selecting one display at a time, and lighting the segments for that display, you can do the opposite of cycling through the 7 segments one at a time, and lighting all the displays that need that segment. That helps reduce the amount of time spent doing the multiplexing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.