This is only a preview of the June 2025 issue of Practical Electronics. You can view 0 of the 80 pages in the full issue. Articles in this series:
Items relevant to "Intelligent Dual Hybrid Power Supply, part one":
Articles in this series:
Articles in this series:
Articles in this series:
Articles in this series:
Items relevant to "Skill Tester 9000, Part 2":
Articles in this series:
|
MAX’S COOL BEANS
By Max the Magnificent
WEIRD & WONDERFUL
ARDUINO PROJECTS
Part 6: shift registers and 8-segment displays
Photo 1: an
early version of
our retro games console
(Photograph by Joe Farr).
56
These modules are available from
multiple suppliers, but the prices on
AliExpress are hard to beat (https://
pemag.au/link/ac53). They are available with two, three, or four digits. I’ve
opted to use three two-digit modules
on my console, but you can choose to
use as many or as few of whichever
types of these devices as you wish.
These displays can be daisy-chained
together, so driving them all will require only three of our Arduino’s pins.
However, before we add them to our
console, let’s refresh our minds as to
how 74HC595 shift registers work.
Do you remember?
These columns are not just about
building cool things but also to learn
lots of interesting and useful stuff along
the way. So even if you have not yet
committed to building the games console, you can still join in with the following experiments.
Let’s start with the 8-segment LED
bar display we introduced in our January 2025 column. The way we left
things is depicted in Fig.1. An image
of the full breadboard along with all
the other components and wires can be
downloaded in file CB-jun25-brd-01.
pdf as part of the June 2025 download
package from the PE website (https://
pemag.au/link/ac54).
Observe that we are using 560Ω current-limiting resistors with green-bluebrown bands. We are using a 5V supply
from the Arduino Uno to power our
breadboard and the red LEDs in our
display have a forward voltage drop
of 2V and a maximum forward current of 20mA.
Using Ohm’s law of V = IR, and rearranging it to give I = V/R, our 560Ω resistors limit the current going through
each LED to (5V – 2V) ÷ 560Ω = ~5.5mA.
In addition to being bright enough
for our purposes here, that is below
the maximum of 6mA that 74HC595
~10
~9
8
7
~6
~5
4
~3
2
TX-1
RX-0
B
efore we plunge headfirst into
the fray with gusto and abandon, let’s briefly set the scene.
We are in the process of constructing
retro gaming consoles that will make
us the envy of our families and friends.
An early prototype is shown in Photo 1.
Our main display is a 14 × 10 array of
tricolour light-emitting diodes (LEDs).
As of last month, we have this display
up and running, although there remain
optimisations we have yet to implement. Soon we will turn our attention
to the 7-segment displays that can be
used to present information like game
levels and scores.
As we discussed in the February
2025 issue, we are going to use prebuilt modules that contain 7-segment
displays, 74HC595 shift registers and
any ancillary components like currentlimiting resistors. 74HC595s are the
same shift registers we used to build
the clock in our Arduino Bootcamp
series (especially the December 2024
column).
By popular demand, the whole series
is now available to purchase as a download, at https://pemag.au/link/ac3d
DIGITAL I/O (PWM ~)
Arduino
Fig.1: the way we left things last time.
Practical Electronics | June | 2025
Listing 1(a): our pin mapping declarations.
shift registers can sink or source on
their outputs.
The way we’ve connected things in
Fig.1, one side of each current-limiting
resistor is connected to the breadboard’s
ground rail. This means a 0 (LOW) or 1
(HIGH) on the corresponding Arduino
pin will switch that display segment
off or on, respectively.
As part of the January column, we
created a program to generate and display 8-bit random numbers (you can
download a copy of this code in file
CB-jun25-code-01.txt).
To be honest, this program is a tad
clunky, but it serves as a springboard
for what’s to come. The first part of the
program that we need to consider is
where we declare the pins we’re using to
drive the display, as illustrated in Listing 1(a). We are using the convention
that the listing number (1 in this case)
corresponds to the numerical part of the
matching code file name (“01” here).
Remember that NUM_SEGS has been
defined as 8, and the elements in the
corresponding 8-element array are referenced as 0 to 7. For example, PinsSegs[0]
and PinsSegs[7] are assigned values of 2
and 9, which are the pins we are using
to drive the right-most and left-most
segments in our display, respectively.
Now let’s consider the loop() function illustrated in Listing 1(b). The
for() loop on line 36 cycles its iSeg
control variable from 0 to 7. For each
pass through the loop, we call the digitalWrite() function on line 38. This accepts two arguments: the number of the
pin we wish to control and the value
we wish to write to that pin.
For the first argument, we are using
the iSeg value to index into our PinsSegs[] array of pin numbers. With respect to the second argument, we are
using the Arduino’s random() function
to generate random 0 and 1 values.
As we discussed last month, this
function accepts two arguments that
we might call min and max. The min
value is inclusive, while the max value
is exclusive, which means the function
will generate a random integer between
min and (max - 1). Since we are using
random(0,2), this will return either 0
or 1, which is like flipping a coin in
the air and calling “heads” or “tails”.
Remember that the Arduino treats 0
and LOW as being synonymous, and
similarly for 1 and HIGH.
Bytes are better
There are many things to dislike
about our current implementation,
Practical Electronics | June | 2025
Listing 1(b):
our code for
generating
random values
bit by bit.
This is not the
most efficient
method, but it
works!
not least that we are
calling the random()
function eight times
to generate each 8-bit
value on the display.
Obviously, it would
be better to call this
function only once.
That’s just what we
are going to do, as
shown in Listing 2(a),
part of the file named
CB-jun25-code-02.txt.
We’ve created a
DisplayByte() function
on line 44. This function has one parameter, an 8-bit unsigned
integer called thisByte
that will contain the
8-bit value we wish
to display.
Once again, we have
a for() loop on line 46
that cycles its iSeg Listing 2(a): generating random values by the byte instead.
control variable from
0 to 7. For each pass through the loop,
on line 48, we use a bitwise AND (&)
to mask out the least-significant bit
of thisByte and test to see if it’s 1.
Then we use the result from this test
to switch the corresponding segment
on or off.
For more details, see the Masking and
the C/C++ Bitwise Operators column on
my website (https://pemag.au/link/ac1q).
The last thing we do in the loop, on
line 53, is to shift the value in thisByte
one bit to the right, thereby preparing Listing 3(a): displaying a binary count.
it for the next pass through the loop.
In the case of the main loop() func- count sequence, for example. Consider
tion, on line 38 we use a single call to Listing 3(a), part of the file named
the Arduino’s random( ) function to CB-jun25-code-03.txt.
generate a random number between 0
All we’ve done is tweak the main
and 255, and we assign that value to an loop( ) function. On line 36, we de8-bit unsigned integer called tmpVal.
clare an 8-bit unsigned integer called
On Line 39, we pass this value into tmpVal and initialise it to 0. Then
our DisplayByte() function to be dis- we use the while() loop on line 38 to
played. Later, on line 40, we pause
cycle around calling our DisplayByte()
for a moment to give ourselves time
function to display the value in tmpVal,
to observe our new random value on after which we increment this value.
the 8-segment display.
Since tmpVal is an 8-bit field, it can
only contain values between 0 and
Count on me
255, after which the next count will
The way we’ve re-architected our return it to 0.
program—in particular, the addiThe while(1) statement is just a cuntion of our DisplayByte() function— ning way to keep on cycling around
allows us to do all sorts of interesting this loop without ever exiting the main
things, like easily displaying a binary loop( ) function. Remember that the
57
duce the shift register into our circuit
is presented in Fig.3; the *1, *2, *3,
and *4 annotations refer to notes, not
c
2
15
a
pin numbers. For this first test, we are
SER
connecting the SER (‘serial in’) input
0 1 2 3 4 5 6 7
d
3
14
SER
to logic 1 via a 10kΩ pull-up resis4
13
e
OE
RCLK
h’ tor. Also, we are connecting the OE
(‘output enable’) input to logic 0 via a
5
12
f
RCLK
0 1 2 3 4 5 6 7
10kΩ pull-down resistor.
6
11
g
SRCLK
We will employ three of the breadOE
board-friendly momentary pushbut7
h
10
SRCLR
ton switches we used in our Arduino
Connection
8
GND
9
h’
Bootcamp columns. By ‘momentary’
a b c d e
f
g h
No connection
we mean these are only closed while
(a) Package
(b) Block diagram
they are being pressed; they immediately return to their inactive (open)
Fig.2: the pinout and internal gates of a 74HC595 serial-to-parallel shift register IC.
states when released.
Arduino treats 1 and true as being state, it clears all the bits in the shift
The SRCLK input is connected to
synonymous; similarly for 0 and false. register to 0.
0V via a 10kΩ pull-down resistor. It’s
Since true is always true, the while
Once the SRCLR input has been re- also connected to one side of one of our
loop never ends!
turned to its inactive (1) state, a rising pushbutton switches, the other side of
edge (a 0 to 1 transition) on the SRCLK which is connected to 5V. When this
Shift over
(‘shift register clock’) input will load switch is pressed, the resulting direct
This is where things start to get super the 0 or 1 value presented to the SER connection to 5V will overwhelm the
exciting (said Max, super excitedly).
(‘serial data’) input into bit 0 of the 10kΩ pull-down resistor to 0V, which
As mentioned earlier, we are going shift register. At the same time, the means the SRCLK input will be preto use a 74HC595 integrated circuit original contents of bit 0 will be loaded sented with a 0 to 1 transition (a ‘rising
(IC), an 8-bit shift register, to drive our into bit 1, the original contents of bit edge’). The RCLK input is connected
8-segment LED display.
1 will be loaded into bit 2, and so on in the same way.
This component is presented in down the line.
By comparison, the active-low
a 16-pin package, as per Fig.2(a). It
One way to visualise this is as a SRCLR input is connected to 5V via
contains two 8-bit registers that oper- bucket brigade (a chain of people acting a 10kΩ pull-up resistor. In this case,
ate independently of each other – see to put out a fire by passing buckets of the other side of the associated switch
Fig.2(b). We can think of the upper reg- water from hand to hand).
is connected to 0V. When this switch
ister as being the shift register itself,
If the outputs from the shift register is pressed, the resulting direct connecand we can view the lower register as were used to drive something like a tion to 0V will overwhelm the 10kΩ
being the output register.
7-segment numerical display directly, pull-up resistor to 5V, which means
A detailed description of this de- that display would flicker as the new the SRCLR input will be presented
vice’s operation is provided in its data values were loaded into the register. with its active (0) state.
sheet (https://pemag.au/link/ac1o), This explains why we also have an
While a range of values would
but a quick overview follows. Let’s output register.
work, we chose the 10kΩ values for
start with the SRCLR (‘shift register
It’s only when we are ready to pre- our pull-up and pull-down resisclear’) input. The bar over its name sent the contents of the shift register
tors to suit the 74HC IC technoloindicates that this signal is active-low. to the outside world that we apply a gy we’re working with. Other chip
When SRCLR is placed in its active (0) rising edge to the RCLK (‘output reg- types might need different values; see
ister clock) input, thereby How to Handle the Inputs to Unused
5V
0V
Logic Gates column for more details
loading the current contents
of the shift register into the (https://pemag.au/link/ac55).
output register.
10kΩ
560Ω
The only remaining con- Updating the breadboard
Unplug the USB cable from your
trol signal to consider is
the active-low OE (‘output Arduino to power everything down.
enable’) input. When this Remove the wires connecting Arduino
input is in its active (0) pins 2 through 9 to the breadboard,
state, the contents of the but leave the wires connecting 0V and
output register will be made 5V on the Arduino to the 0V and 5V
*1 OE
available to the outside rails on the breadboard.
a b c d e f g h
Add the 74HC595 to the breadboard
world. By contrast, when
*2 SRCLK
SER 74HC595
h’
this input is in its inactive as illustrated in Fig.4 (an image of
*3 RCLK
*1 *2 *3 *4
(1) state, the outputs will the full breadboard is available in the
*4 SRCLR
be effectively disconnect- downloadable file named CB-jun25ed from the outside world brd-02.pdf). Observe that the notched
(in our case, we will set it end of the package is shown on the
so the outputs are always left, which means pin 1 is in the lower
left corner and pin 16 is in the upper
enabled).
left corner.
0V
5V
Although this is the opposite of the
Adding the 74HC595
10kΩ
A schematic showing the way we did things with our Arduino
Bootcamp clock, it’s the way chips are
Fig.3: this circuit uses buttons to control the 74HC595. way we are going to intro-
b
58
1
16
VCC
SRCLR
SRCLK
Practical Electronics | June | 2025
Top view
104
74HC595
Side view
Fig.4: adding the shift register to our breadboard.
usually orientated on a breadboard or
printed circuit board (PCB).
Make sure to add the red wire connecting pin 16 (VCC) to the 5V rail
and the black wire connecting pin
8 (GND) to the 0V rail. Also add the
10kΩ pull-up resistor between pin
14 (the SER input) and the 5V rail,
and the 10kΩ pull-down resistor between pin 13 (the OE input) and the
0V rail.
While you’re at it, add a decoupling/
bypass ceramic capacitor as shown.
As we discussed in the August 2024
column, these components aren’t polarised, so we can connect them either
way round. A good rule of thumb is
one 100nF (0.1µF) capacitor per IC.
This should be positioned between
the 5V and 0V rails as close to the red
wire as possible.
The “104” annotation on the capacitor represents 10 × 104 = 100,000,
measured in picofarads (pF), which
equates to 100nF.
Reconnect the USB cable to power
everything up, then use your multimeter to verify that you see 0V on
pins 8 and 13, and 5V (give or take)
on pins 16 and 14.
Power everything down again, then
connect the outputs from the shift register to the inputs of the 8-segment
display as illustrated in Fig.5. Observe the three wires connected to
the RCLK, SRCLK and SRCLR inputs.
In the fullness of time, we will be
driving these signals from our Arduino. First, however, we are going to add
the pushbutton switches from Fig.3
as illustrated in Fig.6 (the full breadboard can be seen in the file named
CB-jun25-brd-03.pdf).
These switches are available in
2-pin or 4-pin packages. Whichever version you are using, make sure
the pins are presented as shown in
Fig.6. With the 4-pin versions, you
can use the continuity setting on your
Practical Electronics | June | 2025
SRCLR
100nF
(0.1µF)
Ceramic
Capacitor
SRCLK
RCLK
74HC595
Fig.5: connecting the shift register IC to the 8-segment LED array.
multimeter (or measure the resistance) to determine which pin pairs
are connected.
It’s important to deploy the switches
with the correct orientation. In the case
of a 2-pin version, if you rotate it by
90°, its associated wires will remain
forever unconnected, irrespective of
how (un)enthusiastically you press
the button. By comparison, if a 4-pin
switch is rotated by 90°, its associated
wires will be permanently connected.
Neither condition will cause any
damage, but the switches won’t operate as expected.
Missing a cunning trick
I just remembered a cunning trick
my friend Joe Farr taught me with respect to pull-up and pull-down resistors. For 74HC-series components (with
which we use 10kΩ to 100kΩ values),
Joe uses 47kΩ (yellow-violet-orange)
for his pull-ups and 22kΩ (red-redorange) for his pull-downs.
This way, when Joe is in the process of debugging a circuit, just seeing
a yellow-violet or red-red colour band
combo tells him that he’s looking at a
pull-up or pull-down resistor, respectively. I would have used this trick
myself if I’d remembered it, but I didn’t,
and I’m not going back to modify all
my diagrams now (sorry).
Let’s run some tests
Our first test is to simply power everything up and observe what happens.
In my case, this was… absolutely nothing. I powered things off and on again
several times… still nothing.
To be honest, this was a bit of a
surprise, and it presented a bit of a
poser, because the 74HC595 isn’t supposed to contain a special power-onreset (PoR) circuit to clear its internal registers and initialise them with
values of 0. Thus, I was expecting to
see a random collection of on and off
LED segments that would be different
every time power was removed and
reapplied.
Currently, I have no explanation for
why I’m not seeing random values. If
you have any ideas, or if your register
behaves differently than mine, please
feel free to drop me a line to share your
thoughts and experiences.
Just to be on the safe side, press
and release the SRCLR (right-hand)
switch and then press and release the
RCLK (left-hand) switch. This will
5V
2-Pin
SRCLR
SRCLK
RCLK
SW1
SW2
10kΩ
10kΩ
10kΩ
SW3
SRCLR
SRCLK
RCLK
4-Pin
GND
RCLK
SRCLK
SRCLR
Fig.6: adding and connecting the switches to our exitsting circuit on the breadboard.
59
(a) Power-up
All segments off
(b) Click SRCLK
Nothing changes
(c) Click RCLK
Segment 0 lights
(d) Click SRCLK
Nothing changes
(e) Click RCLK
Segment 1 lights
(f) Click SRCLK
Nothing changes
(g) Click RCLK
What happened?
(h) Click SRCLR
Nothing changes
(i) Click RCLK
All segments off
Fig.7: testing the shift register.
ensure that all our segments are off,
as illustrated in Fig.7(a).
Remember that we’ve permanently
connected the SER (‘serial in’) input
to logic 1 (5V). Press and release the
SRCLK (middle) switch to load this 1
into bit 0 of the shift register. Observe
that nothing happens on the display as
illustrated in Fig.7(b). Now press and
release the RCLK (left-hand) switch.
This copies the contents of the shift
register into the output register.
What we are expecting to see is only
the first segment light up as illustrated
in Fig.7(c). Just for giggles and grins,
let’s assume that this is what actually
happens.
Press and release the SRCLK switch
again. Observe that nothing happens on
the display, as illustrated in Fig.7(d).
Now press and release the RCLK switch
again. We expect to see two segments
active as illustrated in Fig.7(e). Once
again, let’s assume that this is what
happens.
Let’s go for broke. Press and release
the SRCLK switch one more time. Nothing happens, as shown in Fig.7(f). Press
and release the RCLK switch one more
time. Let’s assume that, instead of the
first three segments being active, the
first six light up, as seen in Fig.7(g).
What just happened?
I’ll tell you in a moment. First, however, press and release the SRCLR
switch. This clears the internal shift
register, but not the output register,
so nothing changes, as illustrated in
Fig.7(h). Finally, press and release the
RCLK switch to copy the contents of the
internal shift register into the output
register, and watch all the segments
turn off as shown in Fig.7(i).
Perform some more experiments on
your own. It may be that your circuit
appears to work as expected most of the
time (I hope not, because that would
diminish the impact of what we are
about to discuss).
Alternatively, you might consistently see multiple segments light up.
Or you could fall in the middle, with
extra segments lighting up occasionally. My own circuit seems to happily
meander between all three scenarios.
So, WTW (what the what) is going on?
Bouncy, bouncy!
The problem is that switches bounce.
That’s just what they do. When we flick
a toggle switch or press a pushbutton
switch, we assume it transitions cleanly
from one state to another; that is, from
on to off or vice versa.
However, due
to factors like
spring action and
mechanical inertia, a switch does
not settle immediately. Instead,
Arduino to the rescue!
I discuss the concept of switch
bounce and ways to mitigate it in excruciating enthralling detail in my
Ultimate Guide to Switch Debounce
columns (https://pemag.au/link/ac56).
We can debounce signals from switches using both hardware and software
techniques. In this case, we’re going
to use our Arduino to debounce the
signals in software.
We’ll start by powering everything
down. Next, we’ll break the direct
connections between the switches
and our shift register, then we’ll insert
the Arduino in the middle as depicted
in Fig.8 (an image of the full breadboard can be found in the file named
CB-jun25-brd-04.pdf).
We can summarise the switch bounce
situation for our SRCLK signal in Fig.9
(the waveforms will be similar for
the RCLK signal and inverted for the
SRCLR signal). The signal coming
from the switch (SW) is normally 0V.
It transitions to 5V when its associated
button is pressed.
SRCLR
SRCLR
SRCLK
SRCLK
RCLK
RCLK
From
Switches
~10
~9
8
7
~6
~5
4
~3
2
TX-1
RX-0
To shift
register
it suffers a series of rapid, unintended
on-and-off connections (or ‘bounces’)
before stabilising. We can visualise
this as dropping a ping-pong ball onto
a hard floor.
Photo 2 shows waveforms captured
on my oscilloscope, reflecting three
switches being activated. From top to
bottom, we see a toggle switch, a pushbutton switch and a limit (micro) switch.
The ‘exciting’ thing is that these
waveforms can change dramatically
between multiple switches of the same
type, or even between the same switch
being activated and deactivated multiple times. Also, a switch’s bounce
characteristics can vary as a function
of temperature, humidity, and age…
to name but a few factors.
To put this into perspective, we’re
having problems controlling a simple
8-segment LED display. Suppose our
pushbutton switch was being used to
control a missile launch system. Do I
need to say more?
DIGITAL I/O (PWM ~)
Arduino
Photo 2: waveforms from three switches being actuated.
60
Fig.8: inserting the Arduino into the switch signal paths.
Practical Electronics | June | 2025
Observe that bouncing can occur
both when the switch is activated
(pressed) and deactivated (released).
For the purposes of our discussions
here, let’s assume that our switches
can bounce anywhere from 1 to 100
times over a period not exceeding six
milliseconds (6ms).
In an ideal world, starting from the
switch being in its inactive state, the
Arduino would detect the leading edge
of the activation and cause its output
to the shift register (SR) to respond immediately. In fact, this is what we are
going to do now. However, in our next
column, we will discover why this approach may not be quite as ideal as we
might suppose.
As seen in Fig.9, we now have two
options. The first is for the output from
the Arduino to follow the input from
the switch (but without any bounce, of
course). The second is for the output
from the Arduino to present a pulse
to the shift register when the switch
is activated, and to subsequently do
nothing until the next activation of
the switch. Let’s consider these options in turn.
Software debounce option #1
I have to say that I’m ashamed about
what I’m about to show you. This is
one of the simplest ways to debounce
our switches, but it’s ‘quick and dirty’;
it lacks elegance, and it’s the opposite
of robust. Still and all, as they say, it
will do the job we need to do here, and
it will provide something to compare
ourselves against in the future.
I just created a rudimentary program
(in the file named CB-jun25-code-04.txt).
Earlier, I said that we would assume
our switch bounce would not exceed
6ms. Based on this, we’ve defined a
delay value called JUST_A_BIT as
being 10ms.
Next, we specify the pins we’re using
on the Arduino to match those shown
in Fig.8. In the setup() function, we say
we want to use pins 2, 3 & 4 as inputs,
and pins 5, 6 & 7 as outputs. We also
set the outputs to their inactive states.
Listing 4(a): software debounce option #1.
Practical Electronics | June | 2025
Inactive
Active
Bounce
Inactive
Bounce
From SW
To SR (option #1)
To SR (option #2)
< 6ms
< 6ms
Wait for bouncing to stop
Fig.9: summarising the switch bounce situation for the SRCLK signal.
In the loop() function, we process
each switch in turn. Consider the way
we handle the SRCLK signal, as illustrated in Listing 4(a). Remember that
the SRCLK signal from the switch is
usually inactive (LOW). Thus, we are
looking for the leading edge when it
first transitions to active (HIGH).
So, every time we go around the
loop, on line 30, we read the pin connected to the switch and check to see
if this signal has gone HIGH, meaning
the switch has been pressed. If not, we
continue to the next switch.
When we see that the switch has
been pressed, we use line 32 to place
a HIGH value on the SRCLK signal to
the shift register. Then, on line 33,
we wait for JUST_A_BIT (10ms) to
ensure that the switch has stopped
bouncing.
Some users will press and release
the switch rapidly, while others may
take a more leisurely approach. Either
way, on line 35, we use a while() loop
to wait for the switch to be released
(think of this as “while the switch is
still active, don’t do anything (or do
nothing)”).
When we see that the switch has
been released, we use line 38 to place
a LOW value on the SRCLK signal to
the shift register. Since the switch may
bounce when it’s released, on line 39,
we once again wait for JUST_A_BIT
to ensure that the switch has stopped
bouncing.
Load this program into your Arduino and verify that everything functions
as expected.
Software debounce option #2
I just made a small modification to
our program, in the file named CBjun25-code-05.txt. As you can see
in Listing 5(a), this is very similar to
option #1. All we’ve done is to move
the statement that places a LOW on
the SRCLK signal to the shift register
from line 38 in Listing 4(a) to line 33
in Listing 5(a).
Now, as soon as the switch is activated, the Arduino presents a positivegoing pulse on the SRCLK signal feeding the shift register. The Arduino then
pauses to let any bouncing stop, waits
for the switch to be released, pauses
again to let any bouncing stop, and then
proceeds to look at the other switches.
Load this new version of our program into your Arduino and verify
that everything continues to function
as we expect.
Clear the display again, then press the
SRCLK switch, followed by the RCLK
switch six times. Once again, this results in the first six segments being lit.
Software debounce option #3
I know… Fig.9 showed only two options. Still, I’ve been saving the best
for last!
Earlier, we noted that one reason for
our 74HC595 chip having both a shift
register and an output register is to prevent the annoying flicker that would
occur if we were using the shift register to drive something like a 7-segment
numerical display directly.
To illustrate this in action, use the
SRCLR and RCLK switches to clear the
Listing 5(a): software debounce option #2.
61
contents of the register and display.
Next, press and release the SRCLK
switch six times (nothing changes on
the display), then press and release the
RCLK switch (the first six segments
light simultaneously).
This separation of registers is great
when we need it, but it’s an encumbrance for what we are currently doing.
For example, use the SRCLR and RCLK
switches to clear the contents of the
register and display.
Now press the SRCLK switch, followed by the RCLK switch six times.
Once again, this results in the first six
segments being lit. I don’t know about
you, but my poor finger is becoming
fatigued by constantly having to press
the RCLK switch after pressing the
SRCLK or SRCLR switches.
Happily, one great thing about doing
things in software is that we can use
one stimulus signal to trigger multiple responses. Suppose, for example,
we modify the actions associated with
our SRCLK and SRCLR signals, as illustrated in Fig.10.
In this case, when we see a rising edge
on the signal from the SRCLK switch,
we can generate a positive-going pulse
on the SRCLK signal to the shift register followed by a positive-going pulse
on the RCLK signal to the shift register.
Inactive
I have no idea why
everyone calls me
"Mad Max"!
Similarly, when we see a falling edge
on the signal from the SRCLR switch,
we can generate a negative-going pulse
on the SRCLR signal to the shift register, followed by a positive-going pulse
on the RCLK signal to the shift register.
I just made the required modifications to our program, in the file named
CB-jun25-code-06.txt. As we see in
Listing 6(a), this is very similar to
Active
Bounce
Inactive
Bounce
SRCLK from SW
SRCLK to SR
RCLK to SR
SRCLR from SW
SRCLR to SR
RCLK to SR
Fig.10: we can modify our software so that one stimulus can trigger multiple responses.
option #2. All we’ve done is to add
lines 34 and 35, which generate a positive-going pulse on the RCLK signal
to the shift register.
If you look at the whole program,
you’ll see that we’ve also made appropriate modifications to the code that
handles the signal from the SRCLR
switch, and we’ve deleted the part
that handles the signal from the RCLK
switch because we no longer need
it (which means we could remove
this switch from our breadboard if
we wished).
Load this new version of our program into your Arduino. Now, when
we press the SRCLK or SRCLR switches, the corresponding actions appear
on the display without our having to
press the RCLK switch. I don’t know
about you, but this makes me a much
happier person.
What’s the point?
We’ve just spent a lot of time pondering switch bounce, but what does
that have to do with the price of tea
in China (as my dear old grannie
used to say)? You must admit that
you are unlikely to find tasty tidbits
of trivia like this in lesser electronics
magazines.
Well, may I invite you to take another look at Photo 1. What do we see
below the main LED display? “Good
golly, Miss Molly!”, I hear you cry,
“There are eight juicy pushbutton
switches that are going to need to
be debounced to enhance our gameplaying experience”. It’s almost as if
we had a plan!
Next time
Listing 6(a): software debounce option #3.
62
I have so many ideas bouncing my
poor old noggin that I barely know
where to start. One thing we are going
Practical Electronics | June | 2025
The Wireless for the Warrior
books are references for the
history and development
of radio communication
equipment used by the British
Army from the very early days
of wireless up to the 1960s.
www.poscope.com/epe
Volumes 1 & 3 are still
available. Order a printed
copy now from:
https:///pemag.au/link/ac20
https:
Useful Bits and Pieces from Our Arduino Bootcamp series
Arduino Uno R3 microcontroller module
Solderless breadboard
8-inch (20cm) jumper wires (male-to-male)
Long-tailed 0.1-inch (2.54mm) pitch header pins
LEDs (assorted colours)
Resistors (assorted values)
Ceramic capacitors (assorted values)
16V 100µF electrolytic capacitors
Momentary pushbutton switches
Kit of popular SN74LS00 chips
74HC595 8-bit shift registers
https://pemag.au/link/ac2g
https://amzn.to/3O2L3e8
https://amzn.to/3O4hnxk
https://pemag.au/link/ac2h
https://amzn.to/3E7VAQE
https://amzn.to/3O4RvBt
https://pemag.au/link/ac2i
https://pemag.au/link/ac2j
https://amzn.to/3Tk7Q87
https://pemag.au/link/ac2k
https://pemag.au/link/ac1n
Other stuff
Soldering guide
Basic multimeter
- USB
- Ethernet
- Web server
- Modbus
- CNC (Mach3/4)
- IO
- PWM
- Encoders
- LCD
- Analog inputs
- Compact PLC
https://pemag.au/link/ac2d
https://pemag.au/link/ac2f
Components for Weird & Wonderful Projects, part 1
4-inch (10cm) jumper wires (optional)
8-segment DIP red LED bar graph displays
https://pemag.au/link/ac2l
https://pemag.au/link/ac2c
Components for Weird & Wonderful Projects, part 2
144 tricolour LED strip (required)
Pushbuttons (assorted colours) (required)
7-Segment display modules (recommended)
2.1mm panel-mount barrel socket (optional)
2.1mm inline barrel plug (optional)
25-way D-sub panel-mount socket (optional)
25-way D-sub PCB-mount plug* (optional)
15-way D-sub panel-mount socket (optional)
15-way D-sub PCB-mount plug^ (optional)
https://pemag.au/link/ac2s
https://pemag.au/link/ac2t
https://pemag.au/link/ac2u
https://pemag.au/link/ac2v
https://pemag.au/link/ac2w
https://pemag.au/link/ac2x
https://pemag.au/link/ac2y
https://pemag.au/link/ac2z
https://pemag.au/link/ac30
- up to 256
- up to 32
microsteps
microsteps
- 50 V / 6 A
- 30 V / 2.5 A
- USB configuration
- Isolated
PoScope Mega1+
PoScope Mega50
* one required for each game cartridge you build
^ one required for each auxiliary control panel you build
Components for Weird & Wonderful Projects, part 3
22 AWG multicore wire kit
20 AWG multicore wire kit
https://pemag.au/link/ac3m
https://pemag.au/link/ac3n
Components for Weird & Wonderful Projects, part 4
5V Buck converter module
9V 2A power supply (optional)
Bench power supply (optional)
to do is enhance our switch debounce
solution to address all the problems I
haven’t told you about yet.
Until then, if you have any thoughts
Practical Electronics | June | 2025
https://pemag.au/link/ac2m
https://pemag.au/link/ac46
https://pemag.au/link/ac48
you’d care to share on anything you’ve
read here, please feel free to drop me
an email at max<at>clivemaxfield.com.
And, as always, have a good one! PE
- up to 50MS/s
- resolution up to 12bit
- Lowest power consumption
- Smallest and lightest
- 7 in 1: Oscilloscope, FFT, X/Y,
Recorder, Logic Analyzer, Protocol
decoder, Signal generator
63
|