74HC595 with 74LS47 hexa code to UNO R3

There are a few small mistakes with spelling, but I think the IDE would eventually warn you.

X :heavy_check_mark:
Void void
HIGHT HIGH

If you want to use this kind of shortcut ("Pin_A", "Pin_B") instead of pin number (6, 5), you have to create the shortcut first.

The official phrase for creating this kind of shortcut is "defining a macro". The very start of your code is a good place to define macros:

#define Pin_A 6

void setup()
{
// set LED pins as output to light, by defaut they output LOW
pinMode (Pin_A,OUTPUT);

It is okay to use pinMode(PIN, INPUT) in setup, but it is also okay to skip it. There is no difference.

The reason is: when Arduino starts, all pins are already INPUT, automatically.

//......................................................................................................................................................
// The schematic for this sketch is on Post n°27. Common cathode UNO 4 IN 8 OUT Aug 26th 2023
//......
// Read conditions at start of void loop
// The display has seven segment and to see the eighth output there is a Led, LED 8
// I can read on display number one to eight and with this led 8, it's A with pin 9 output.

# define Pin_A 6
# define Pin_B 5
# define Pin_C 4
# define Pin_D 3
# define Pin_E 2
# define Pin_F 8
# define Pin_G 7
# define Pin_H 9

// now BP1 and BP2 Push Buttons, see the schematic Post N°27 
#define Pin_BP1 18
#define Pin_BP2 10 

void setup()
{
// set LED pins as output to light, by defaut they output LOW
pinMode (Pin_A,OUTPUT);
digitalWrite(Pin_A, HIGH);
pinMode (Pin_B,OUTPUT);
digitalWrite(Pin_B, HIGH);
pinMode (Pin_C,OUTPUT);
digitalWrite(Pin_C, HIGH);
pinMode (Pin_D,OUTPUT);
digitalWrite(Pin_D, HIGH);
pinMode (Pin_E,OUTPUT);
digitalWrite(Pin_E, HIGH);
pinMode (Pin_F,OUTPUT);
digitalWrite(Pin_F, HIGH);
pinMode (Pin_G,OUTPUT);
digitalWrite(Pin_H, HIGH);
pinMode (Pin_H,OUTPUT);
// digital input for BP1 on entry A4(pin18), and digital input BP2 on entry
// D10 on the Uno board
//........................................................................................................................
}

void loop()
// read voltage on Button PB1to valid, and, BP2 to erase or reset ,  the
// levels into SW1 are no operande
// When there is a number on display and Led 8, you can
// use BP2 to erase all leds. And after you can choose a code Hexa with
// switches into SW1.
// this code will be memorize in UNO When you push on BP1.
// if you change the code Hexa without erase with BP2, this code will not be
// memorized in Uno, even if you press on BP1.  
 
{
        bool button_PB1= digitalRead(18);  //   18 or A4 ?
        bool button_PB2= digitalRead(10);
// if the PB2 "erase reset" is pressed (connect to GND)
       if(button_BP2 ==LOW)
           {
// set the LED pins to LOW voltage level (no current flow, no light). 
              digitalWrite(Pin_A, LOW);
              digitalWrite(Pin_B, LOW);
              digitalWrite(Pin_C, LOW);
              digitalWrite(Pin_D, LOW);
              digitalWrite(Pin_E, LOW);
              digitalWrite(Pin_F, LOW);
              digitalWrite(Pin_G, LOW);
              digitalWrite(Pin_H, LOW);
//   digital input for BP1 on entry A4, Pin 18;   and digital input BP2 on entry
//   D10 Pin 10 on the Uno board


         }
// to be continued 
}

Hello toddnz,

I have fixed my mistakes in this sketck.

This Post n°42 will be completed day after day.
to be contined

Best regards, JACK

Hello toddnz,

You have readed :
"It is okay to use pinMode(PIN, INPUT) in setup, but it is also okay to skip it. There is no difference.

The reason is: when Arduino starts, all pins are already INPUT, automatically."

My two requests ;
First
Then, when UNO start I have not Push on BP1. The Code would be at this time , 1111
and display "F". Yet the 4 resistors R9 R10 R11 R12 are fot grounding.
How many time the "F" will be displayed if I d'not Push on BP2

Second
Or the 4 resistors are put so that the 4 inputs are at LOW.

And have you read new Post n° 42

to be continued
Best regards
JACK

Before the user presses PB1 or PB2 for the first time, their code does not run.
At the start, the number on the LED is set by the setup() code.

I see that in setup(), it still uses digitalWrite(Pin_A, HIGH). I think this HIGH should be LOW, to have the LED off at the start. Maybe we forgot to change this part when changed to common cathode?

Let me know if I misunderstood this question.


I'm not sure exactly what the request is. Are you asking about code, which, at start-up, checks the 4 inputs, and sets the LED one time, before the user pushes any buttons?

The aim setup() code you working on now, is to start-up with the LED blank.
If, instead, you want to read the inputs and update the LED automatically at start-up, you need to use the same code from the PB1 press section, but also in setup.

If this is something you want, instead of just copying all the code twice, it is a good idea to write a "function". A function is a reusable piece of code, so you can type it just one time, and use a shortcut in both places (the PB1 section and also in setup())

Re toddnz,

Yes, ok when cathode is at Ground on my second schematic ; the Anode Ground will be LOW on " Pin_A, LOW" on set up Post 42 it is write (Pin_A, HIGH);
I must then modify post n°42.

For your second request,
explications;
Uno card, starting the setup is prioritary on les positions switches of SW1; see second schematique / two sitches are ON to do 0011 number 3;
Uno card will ignore these levels when starting UNO;

In last paragraph, you prefered a Sujet only for the totality of this sketch ?
is that it ? I do that in Post n°42. By complement lines.

Now, I added in the set up BP1 and BP2 perhaps mistakes with names of pins 10 and 18.Read in void first line , bool 18 or A4 ?
See Post 42 who was completed.
to be continued tomorrow
Best regards Jack

Ah, I see. I did not notice before. The normal style for this forum is to make a new post for every code change. "Edit post" is only used for a small change, like spelling mistake. So I did not realize that you put new code in the old post.


In Arduino, "18" or "A4" are exactly the same, for every purpose. It is most common to type "A4", but this is just a preference. If you prefer to type "18", there is no issue.


This code is not correct, and I am not sure of the intended purpose.

  • digitalRead(Pin_18,HIGH)
    The purpose of digitalRead is to check if a pin is HIGH or LOW.
    You type the code for digitalRead, but you are not using the result. It should have some purpose, for example:

    if ( digitalRead(18) ) 
    {
        // Do something here
    }
    

    Also, I see that you put two things inside the (). For digitalRead, there should be only one thing. Here is the official manual for digitalRead

  • pinMode (Pin_18,INPUT)
    At start-up, this code is not required. But if sometime it is required, you should place it before digitalRead, not after. Set the pin's mode to INPUT, before you can use it as an input.

    I see also that you type "Pin_18". I'm sure this is just a small mistake, but you should type either "18", or "Pin_BP1" (the macro you defined at start of code).


I didn't realize before about this requirement. It is not difficult, but it will require some extra code.

Here is a demonstration of code to "lock" a button, until user presses erase:

#define PIN_UPDATE 2
#define PIN_ERASE  3

// When a variable (like "locked")  is placed outside setup() or loop(),
// it keeps its memory between loops.

bool locked = false;

void setup() {
  // (No setup code needed)
}

void loop() {
  bool update_pressed = digitalRead(PIN_UPDATE);
  bool erase_pressed = digitalRead(PIN_ERASE);

  // Check if both "update_pressed", and also not "locked"
  if (update_pressed && locked == false) {
    // ( LED update code would be here ), but also:
    locked = true;
    // Now, this section can't run again, because locked is true
  }

  else if (erase_pressed) {
    // (Erase code would be here), but also:
    locked = false;
    // Now, the update code can run again, because locked is false
  }

}

Hello toddnz,

Thank you for your reply.
Iam studing all your lines at the moment.
I understood your first two answers.

I am at the line "if (digitalRead(18) . In the setup I wrote digitalRead(Pin_18, HIGH) . for BP1.

Should I clear this in my setup, for BP1 ?? And also for Pin10 BP2 ??

to be continued
Best regards
Jack

Yes, those four lines should be cleared.

Re toddnz,

Tks, I go in Post 42 into setup to clear this 4 lines

Now I am here

..................That whill be into void loop ?

to be continued
Best regards
Jack

Ah, sorry. No, this will not be in your code.

This was just to show a normal purpose for digitalRead. I wanted to help explain why your digitalRead was wrong in setup, but you already cleared these four lines in post #48, so now it is not a problem.

Please do not edit #42. Please make a new post for every code revision.

Hello toddnz,

Thanks for reply,
OK, I now do the code in each Post. The post 42 will no longer be completed.
But can you tell me if Post #42 is entirely correct as it is.
I think no, because there are not BP1 and BP2 in setup.
Below will the lines be added ?

pinMode(BP1, INPUT);
pinMode(BP2, INPUT);

/* complement {
pinMode(BP1, INPUT); // here Pin (18) is an analogic entry, so should I write
instead of INPUT / digitalINPUT ??
pinMode(BP2, INPUT);
But in Post 42 there are # define for Pin 18 and # define for Pin 10.
*/
To be continued
Best regards
Jack

I don't notice any errors so far. It might need some changes eventually (see last part of post #46).

It is not necessary, because Arduino automatically sets every pin to INPUT at start-up. It is not necessary, but you can add these two lines if you wish. It will make no difference.

I can understand your thought, but no, the correct code is:

pinMode(Pin_BP1, INPUT);
pinMode(Pin_BP2, INPUT);

There are only 3 possible modes:

  • OUTPUT
  • INPUT
    • (Doesn't allow much current to flow)
  • INPUT_PULLUP
    • (Same as INPUT, but automatically adds pull-up resistors, inside the IC)

Mode INPUT is suitable for using both digitalRead() and analogRead().

Hello toddnz,
Tks for the reply,

ok I understand your explanations.

Now I do the setup, here

void setup
                  //this firts lines are copy of 42 Post

digitalWrite(Pin_A, HIGH);
pinMode (Pin_B,OUTPUT);
digitalWrite(Pin_B, HIGH);
pinMode (Pin_C,OUTPUT);
digitalWrite(Pin_C, HIGH);
pinMode (Pin_D,OUTPUT);
digitalWrite(Pin_D, HIGH);
pinMode (Pin_E,OUTPUT);
digitalWrite(Pin_E, HIGH);
pinMode (Pin_F,OUTPUT);
digitalWrite(Pin_F, HIGH);
pinMode (Pin_G,OUTPUT);
digitalWrite(Pin_H, HIGH);
pinMode (Pin_H,OUTPUT);
                      // I now add the inputs buttons
pinMode (Pin_BP1 INPUT);
pinMode (Pin_BP2 INPUT);
                     // To finish the setup I don't add
                     // anything for A0 A1 A2 A3      ????? 
``
Best regards
Jack

Looks good so far.

You don't need anything for A0, A1, A2, A3. They are not used.

Re toddnz,

I read in my ide 2.1.1 and I do an photo screen,

to be continued on forum
Best regards, Jack.

Hello toddnz,

To day I continu for the void,
I think to memorize for each code HEXA the outputs ; I think I can use " Case " for it.
so for 0010 = 2
Number two will be displayed with 5 segments, Pin_A, Pin_B Pin_G Pin_E Pin_D
in " Case " I memorize 5 lines only, lines HIGH

to be continued
Best regards Jack

Photo screen is not so good, because can't copy to my computer to test.

The IDE has a button to help: Edit > Copy for Forum (Markdown)