Silicon ChipMax’s Cool Beans - February 2023 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Back Issues: Hare & Forbes Machineryhouse
  6. Publisher's Letter: What is it about Tesla?
  7. Feature: A thousand words by Mark Nelson
  8. Feature: The Fox Report by Barry Fox
  9. Feature: Net Work by Alan Winstanley
  10. Project: Solid-State Flame Discharge by Flavio Spedalieri
  11. Project: Cooling Fan Controller & Loudspeaker Protector by John Clarke
  12. Project: Driveway Gate Remote Control by Dr Hugo Holden
  13. Project: Geekcreit’s LTDZ V5.0 Spectrum Analyser by Jim Rowe
  14. Feature: KickStart by Mike Tooley
  15. Feature: Make it with Micromite by Phil Boyce
  16. Feature: Circuit Surgery by Ian Bell
  17. Feature: Max’s Cool Beans by Max the Magnificent
  18. PCB Order Form
  19. Advertising Index

This is only a preview of the February 2023 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Max’s Cool Beans By Max the Magnificent Arduino Bootcamp – Part 2 I don’t know about you, but I’m really excited to be writing this series of Arduino Bootcamp columns. The only problem is that I have so many thoughts bouncing around in my poor old noggin that I don’t know where to start. I’ll tell you what, let’s kick off by lighting up some more LEDs because doing so rarely fails to delight, but first... Captain’s log an exhaustive list. You should use your logbook to keep track of anything that might conceivably be of use in the future. For example, algorithms, equations and formulas (eg, calculating the value of an LED’s current-limiting resistor), suppliers and part numbers (and prices) of components, experiments you may wish to perform and projects you may want to build in the future… the list goes on. I meant to make mention of this before, Is it ‘a LED’ or ‘an LED’? but I was so excited by the thought of a When I pen my columns, I usually say flashing LED that it went clean out of my ‘a LED.’ Later, however, when I come to mind. Engineers (the good ones) always check the final laid-out piece, I find that keep a logbook in which they record PE’s editor and publisher, the nefarious items like ideas, decisions, settings and illustrious Matt Pulzer, has replaced these results, to name but a few. instances with ‘an LED.’ In the case of decisions, for example, Which of us is in the right? Well, as if you can think of three ways to do fate would have it, both styles are corsomething, make brief notes describrect. It all depends on whether the writer ing those techniques (or just list them (or speaker) is thinking ‘LED’ to rhyme if they are well known to you). Also, in with ‘bed,’ in which case ‘a LED’ is the addition to recording the approach you appropriate usage, or if we are thinking of decided to use and why you opted for it as being spelled out as ‘L-E-D’ (which this choice, note your reasons for not sounds like ‘ell-ee-dee’), in which case using the other options. ‘an LED’ is the way to go. With respect to settings, one example is my laser cutter and engraver. When Who’s on top? I’m experimenting with new materiAre you, like me, thinking of the classic als and different head speeds and laser ‘Who’s on first?’ comedy routine made power values, I note down what works famous by American comedy duo Abbott (and what doesn’t) for future reference. and Costello? Well, this is nothing to do When it comes to experiments, in adwith that. dition to documenting the test setup (a Remember that LEDs are polarised few sketches and/or photographs never components, which means the way in hurts), don’t record only the results which they are connected is important. you were expecting (hoping) to see, For an LED to turn on and conduct (and but also keep track of anything that went awry. Sometimes, years later, you’ll 5V 5V learn something a new and think, ‘Just k a moment, I wonder a if…’ As Isaac Asimov k famously said, ‘The GND GND most exciting phrase to hear in science, the one that heralds new GND GND From From discoveries, is not Arduino Arduino 5V 5V Eureka! (I found it!) (a) Resistor on LED’s anode (b) Resistor on LED’s cathode but, ‘That’s funny…’ The points I just mentioned don’t form Fig.1. It doesn’t matter ‘who’s on top.’ 62 illuminate), its anode (a) terminal must be at a higher (more positive) potential than its cathode (k) terminal. (In the case of an individually packaged LED, the cathode terminal is the shorter lead located on the flat side of the package.) By comparison, resistors are non-polarised, which means we can happily connect them either way round. In my previous column (PE, January 2023), when we came to set up our breadboard, we located our current-limiting resistor between the LED’s anode and the 5V rail (Fig.1a). Had we wished, however, we could have placed this resistor between the LED’s cathode and the GND (0V) rail (Fig.1b). Either way, the LED would turn on and light up. (If your LED is too bright, you can increase the value of your current-limiting resistor, which will decrease the current and dim the LED.) You may wonder why I’m taking the time to waffle on about this here. All will become clear in the fullness of time when we start to talk about ‘common-anode’ and ‘common-cathode’ devices containing multiple LEDs. 7-segment displays The first light-emitting diodes (LEDs) to display in the visible spectrum appeared on the scene in 1962. At that time, you could have any colour you wanted, just so long as that colour was red. For the first few years these devices were horrendously expensive, depleting one’s bank account by around $200 apiece (Eeek!). Fig.2. 7-segment display. Practical Electronics | February | 2023 By the early 1970s, however, the price had fallen in the US to around five cents each, which was much more affordable. These days, of course, you can pick them up for just a couple of cents in the US (or pennies in the UK), which makes me very happy indeed (as I always say, ‘Show me an LED flashing and I’ll show you a man drooling’). A 7-segment display is a form of electronic device whose primary purpose is to display the decimal numerals 0 through 9. Each segment has its own source of illumination. As early as 1910, a 7-segment display illuminated by incandescent bulbs was used on a signal panel in the boiler room of a powerplant. LED-based 7-segment displays started to appear on the scene circa the early 1970s. Almost immediately, they began to pop up in things like pieces of test equipment, 4-function calculators, and wrist watches (anyone brandishing such a watch was deemed to be a king, or queen, of cool). These displays come in all sorts of shapes, sizes and configurations. In the case of single-digit displays, for example, some have their pins positioned down the sides, while others – like the ones we’ll be using – have their pins located at the bottom and the top (Fig.2). In Part 1 of this series, I mentioned that I found a pack of 10 single-digit common-cathode 7-segment displays for £7.49 on Amazon in the UK (https://amzn.to/3Afm8yu). I’m using something similar that I found on Amazon in the US, which is where I currently hang my hat (https://amzn.to/3GgxJAT). How do we determine which pins are connected to what? That’s a good question; I’m glad you asked. Sad to relate, the entries for these components on Amazon don’t have any useful information to impart on this topic. Printed on the bottom of my own devices I see the legend ‘CL5611AH.’ I had a quick Google (it’s alright, no one was looking) searching for ‘CL5611AH Datasheet’ and found one (https://bit.ly/3hKOpq2) that contained almost everything one might wish to know… apart from the pin assignments. Next, I searched for ‘CL5611AH Pinout,’ which led me to a bunch of useful diagrams, allowing me to create my own representation (Fig.3). (This is the sort of thing you might want to document in your engineer’s logbook.) As we see, the segments are arranged as a rectangle formed from two vertical segments on each side accompanied by one horizontal segment on the top, in the middle and at the bottom. In the physical device, this rectangle is often presented in an oblique (slanted) fashion, which is aesthetically pleasing and aids readability. Think of it as slightly ‘italic’. The segments are GND referred to by the letG F A B ters A to G. An op10 9 8 7 6 tional decimal point Multiple anodes (an ‘eighth segment’, A 7 6 4 2 1 9 10 5 referred to as ‘DP’) is F B A B C D E F G DP used for the display of non-integer numbers. G Each segment has its GND E C own LED. The reason we call 3,8 D DP Common cathode this a ‘single-digit dis1 2 3 4 5 play’ is that it can display only a solitary E D C DP numeral (it’s possiGND ble to get displays boasting two, four, Fig.3. Segment names and pin numbers for our 7-segment display. or more characters). The reason we employ the ‘commononly option is to use a separate currentcathode’ nomenclature is that all the limiting resistor for each LED. LED cathodes are connected together Make sure your Arduino is powered inside the device. In the case of our comdown (ie, not connected to your component, the common cathode is brought puter via its USB cable). Also, make sure out on two pins (3 and 8), either or both that the green LED on the breadboard is of which can be connected to GND (0V). wired up as shown in Fig.1a or Fig.1b. Now plug your 7-segment display into your breadboard (Fig.5). Next, use two Testing the segments by hand black jumper wires to connect pin 3 of Before we connect this display to our the display to the lower GND rail and Arduino Uno, let’s make sure that (a) pin 8 to the upper GND rail. Why conthis is indeed a common-cathode disnect both these pins since they are alplay, (b) all of the segments work, and ready connected inside? Why not? The (c) we’ve assigned the correct pin numadvantage of connecting both is that it bers to the segments. provides us with some redundancy. If one The first point to note is that we’re of our black jumper leads is bad (broken going to need a separate current-limiting inside), for example, then the other will resistor for each LED (Fig.4). If you cast suffice. Do we really need both in this your mind back to our earlier discussions case? No. But if I were creating a safetywhere we stated, ‘It doesn’t matter who’s critical or mission-critical system and I on top,’ you may be wondering why we had the opportunity to use two conneccan’t use just one resistor on the cathtions, I would do so, ‘just in case’ (this ode. In fact, we could if all of the LEDs is a good mindset to adopt). are identical (which they are) and if we The Amazon webpage associated with wished to light only a single segment at the 7-segment displays I’m using notes a time (which we don’t). that each LED’s forward voltage (VF) is Let’s play a thought experiment. Let’s consider what would happen if we were to 2V and its forward current (IF) is 20mA connect a single current-limiting resistor (0.02A). This is typical for red LEDs of to our common cathode. Each LED that’s this type, so we’re reasonably safe to active will draw current. One active LED assume that it also applies to your display. will draw a certain amount of current, two We discussed the equation we use to active LEDs will draw more current, and calculate the value of our current-limiting so on (I’m simplifying a bit here). The voltresistor in our first column. Since we are age dropped across a resistor is a function working with a 5V supply, the currentof the current passing through that resislimited resistors we need to use here are tor. Since the value of our resistor is fixed, from Ohm’s law (V = I × R) we know that 5V increasing current will increase the voltage being dropped across the resistor. In turn, this will result in less voltage being 7 6 4 2 1 9 10 5 available for the LEDs, which will result A B C D E F G DP in dimmer segments. The result is that the brightness of the characters will depend on the number of segments used to form GND them. The number 1 (which is formed by 3,8 lighting two segments), for example, will GND be brighter than the number 8 (which requires all seven segments). Since we really want all our characters to be disFig.4. Each LED requires its own currentplayed with the same brightness, our limiting resistor. Practical Electronics | February | 2023 63 F E G B D C From Arduino A DP GND 5V Fig.5. Wiring up the breadboard. calculated as (5V – 2V) / 0.02A = 150Ω. This value of resistor will have browngreen-brown colour bands. Add eight of these resistors to the eight pins on the display that are connected to the A through G and DP segments, as illustrated in Fig.5. Earlier, we noted that resistors are non-polarised, which means we can happily connect them either way round, so why have I shown them all connected in the same way in this figure (and why do I do the same on my breadboard in the real world)? One reason is that I find this to be aesthetically pleasing. (Also, like many engineers, I have a hint of a sniff of a whiff of the obsessive-compulsive about me!) We’re almost there, plug one end of a red jumper wire into the 5V power rail and leave the other end as a flying lead, as shown in Fig.5. Now power up your Arduino and make sure the green LED on your breadboard is lit, thereby informing us that power is still making its way to the board. Plug the loose end of the flying red lead into the hole marked ‘A’ in Fig.5, and make sure that the A segment lights up (any hole in this column will suffice). Repeat this for all the other segments to confirm our display is tickety-boo. Now we’re really ready to rock n’ roll! wrong, we wired things up incorrectly, we used a common-anode display by mistake…) or is there something skewwhiff with our software? This is the same problem professional engineers face when designing realworld systems. The solution is to (as far as possible) divide the problem into smaller ‘chunks’ and to take things one step at a time. In our case, except for the flying lead, we would have wired things up as shown in Fig.5 anyway. Performing the hand testing literally added no more than a minute to the overall process, but – in addition to being fun in its own right – the result of this testing means we now have a high level of confidence that our hardware works as expected. In turn, this means we can devote our full attention to the software. Preparing to use the Arduino Unplug the USB cable from your Arduino, remove the flying lead from the breadboard and add eight jumper wires to connect the display to the Uno, as illustrated in Fig.6. I’ve shown these jumpers as all being orange in this diagram for simplicity. In the real world, with my own setup, I used two groups of purple, orange, yellow and blue wires because this makes it a lot easier to check what’s connected to what (and what isn’t) if things don’t work as expected. The reason we are using digital I/O pins 2 to 9 on the Uno (as opposed to pins 0 through 7) is that, even though we always say this microcontroller has 14 digital pins numbered from 0 to 13, in practice we typically reserve pins 0 and 1 to perform any serial communications with our host computer. (Observe the annotations associated with pins 1 F A G E B DP D C AREF GND 13 12 ~11 ~10 ~9 8 7 ~6 ~5 4 ~3 2 TX-1 RX-0 Jumper wire DIGITAL IN/OUT (PWM ~) Fig.6. Connecting the Arduino. and 0 on the Uno circuit board; TX = Transmit and RX = Receive.) When we upload programs from our host computer to the Arduino, for example, the system uses these pins to do the job. Now, plug your USB cable back into your Uno. As you may recall, our final program in Part 1 of this series flashed an LED connected to digital I/O pin 6. If this program is still loaded in your Uno, you should see segment D flashing on your 7-segment display. I’m sorry, I need a moment… flashing LED… man drooling… and I’m back. In our very first program in Part 1, we explicitly specified the number of the digital I/O pin we wanted to use when we called the pinMode() and digitalWrite() functions. Later, we used a #define preprocessor directive to associate a constant label we called PIN_ LED with the number 6 (Line 1 in Listing 1a). Another technique is to declare the pin we wish to use as being a variable Divide and conquer In the preceding section we tested our display’s segments by hand. In the following sections we’re going to drive them using our Arduino Uno. So, why did we bother with the hand-testing? Well, suppose we had omitted the hand testing and proceeded directly to Arduino control. Now, suppose we created a program to drive the display, ran it, and… nothing happened. Here we sit with a display that’s doing nothing furiously. What’s our next move? The issue we have now is that we (a) PIN_LED as a constant (b) PinLed as an integer variable don’t know where the problem is – perhaps there’s something wrong with our hardware (we got the pins Listing 1. Alternative ways of defining the pin we wish to use. 64 Practical Electronics | February | 2023 of type int (integer) and assign it A B C D E F G DP a value of 6. Let’s PinLed 6 PinsSegs 2 3 5 6 7 9 8 4 call this variable 0 1 2 3 4 5 6 7 Index (a) Single integer (b) Array of eight integers PinLed (Line 4 in Listing 1b). RememFig.7. Single-integer variable vs. array of integers. ber that we need to use a semicolon ‘;’ character to terminate this statement (we don’t need semicolons with #define directives). In the case of the #define approach, before the nitty-gritty compilation commences, the preprocessor will replace any instances of PIN_LED it sees in the body of the program with the number 6. By comparison, in the case of our new technique, when we compile and run the program, wherever we reference PinLed, the program will use whatever value is currently assigned to PinLed (the number 6, in this example). It’s best that you enter this new version of our program by hand (you need the practice) into your Arduino integrated development environment (IDE), then upload it into your Uno and ensure that segment D on your display is still flashing. Should you run into any problems, you can download my version of Listing 1b (file CB-Feb23- 01.txt) from the February 2023 page of the PE website: https://bit.ly/pe-downloads Name Name Associated segments Being conventional Any of our own names and labels that we declare in a C/C++ program can contain any mixture of uppercase and lowercase alpha characters (‘a’ to ‘z’ and ‘A’ to ‘Z’), numeric characters (‘0’ to ‘9’), and underscore ‘_’ characters (no spaces or other symbols). Also, they must start with an alphabet character or an underscore character, not with a number. You will find that your life is a lot easier if you adopt a naming convention and stick to it. This will greatly facilitate your reading and the understanding of your code in the future. If you end up writing programs for a company, they will detail the convention they wish you to use. In the case of your own programs, you can define your own rules. You don’t have to follow my convention, but I will say that I’ve evolved it over many years (and many mistakes). First, in the case of #define constant labels like PIN_LED, based on what I’ve seen from my professional programmer friends, I use only uppercase alpha characters along with numbers and underscores. By comparison, in the case of variable names like PinLed, I use a typographical convention known as ‘camel case’ (sometimes stylised as ‘camelCase’ or ‘CamelCase’), in which words are separated by a single capitalised letter, such as GoodGollyMissMolly, for example. Furthermore, I use what’s called ‘upper camel case’ (a.k.a. ‘Pascal case’ or ‘bumpy case’) with an initial uppercase letter for global variables (like PinLed) that can be seen throughout the program. By comparison, although this isn’t something we’ve done yet, I use ‘lower camel case’ with an initial lowercase letter for local variables (like myLed) that are declared inside a function and can only be seen within that function. Driving each segment in turn If we return to Fig.6, we see that our display segments are connected to our Arduino pins as follows: A = 2, B = 3, C = 5, D = 6, E = 7, F = 9, G = 8 and DP = 4. These connections fell out this way because we wanted to make our diagram look pretty, but it’s resulted in an out-of-order sequence. Happily, this isn’t a problem because we can easily resolve things in our code. One thing we could do would be to declare the pins driving each of our segments as individual integer variables, for example: int PinSegA = 2; int PinSegB = 3; int PinSegC = 5; : etc Practical Electronics | February | 2023 Listing 2. Using an array of pins. Although simple to understand, this would quickly become a pain because we would be obliged to capture the rest of our code in a verbose style. Try writing a program to turn each segment on and off using these individual variable declarations and you’ll soon see what I mean. In fact, just for giggles and grins, I’ve written this program for you. It came in at 66 lines of code (file CB-Feb23-02.txt). There’s a better way. What we are going to do is create an array of integers called PinsSegs[] in which we can store the numbers of all the pins associated with the segments. Since we know that our display has eight segments (including the decimal point), we could employ the following declaration: int PinsSegs[8] = {2,3,5,6,7,9,8,4}; However, using a raw numeric literal like 8 in this way without any explanation as to its origin and meaning is not a good idea. Programmers call this sort of thing a ‘magic number’ because it’s appeared from nowhere. In addition to making programs less readable, using magic numbers (other than 0 or 1) also makes them more difficult to update and maintain. A better solution is shown in Listing 2, in which we use a #define to declare a constant called NUM_SEGS that we associate with the number 8 (Line 3). We then use this definition as part of our integer array declaration (Line 5). We will consider this program in a little more detail in a moment. First, use the Arduino’s IDE to capture this code and upload it into your Arduino Uno, then sit back and bask in the joy of watching your display’s segments flash on and off in turn following the sequence A, B, C, D, E, F, G, DP (file CB-Feb23-03.txt). An array of possibilities Arrays can be a little bit tricky to wrap your brain around the first time you see them, so let’s take a moment to ensure we’re all stomping our feet to the same drumbeat. Consider our earlier program in which we declared an integer 65 Components (from Part 1) LEDs (assorted colours) https://amzn.to/3E7VAQE Resistors (assorted values) https://amzn.to/3O4RvBt Solderless breadboard https://amzn.to/3O2L3e8 Multicore jumper wires (male-male) https://amzn.to/3O4hnxk Components (from Part 2) 7-segment display(s) https://amzn.to/3Afm8yu for (initialize; test; update) { // Body of the loop } Listing 3. Introducing the random() function. variable PinLed and assigned it a value of 6. One way to visualise this is as a box containing an integer (the number 6 in this example) as shown in Fig.7a. By comparison, when we declare an array of integers like our PinsSegs[], we can envisage this as comprising a collection of boxes sharing a common name. Since we’ve declared our array as being of size 8, these boxes are numbered 0 to 7, as illustrated in Fig.7b. If we wish to access any of these elements, we can do so using a combination of the variable name and an index into the array. For example, if we wanted to change the number of the pin associated with our DP segment from 4 to 11, we could do so using: The header comprises three semicolon-separated fields that we might call initialise, test and update. We commence by performing any initialisation. This step is performed only once when the loop is first called. In our case, we declare an integer variable called iSeg and initialise it to 0. As an aside, a lot of people use single-letter variables like i and j to control these loops. This is certainly more concise, but experience has taught me that its usually better to use a minimum of three letters because this makes the code more meaningful and reduces errors. The test is used to evaluate a condition. In our case, this involves testing that the current value of iSeg is less than NUM_ SEGS, which we defined as being 8. This test is performed at the start of each iteration of the loop. If the test fails (ie, returns a ‘false’ value, where I’ll explain what we mean by ‘true’ and ‘false’ in a future column), then the loop terminates – otherwise, any statements in the body of the loop are executed. After the body of the loop has been executed, the update portion of the header is… well… updated. In our case, our update expression is iSeg++ (which is the same as saying iSeg = iSeg + 1). As soon as the update has been performed, the loop returns to re-evaluate its condition, and off we go again. Feeling random As one final experiment for this column, let’s modify our program to randomly turn the display segments on and off (Listing 3, file CB-Feb23-04.txt). As we see, all this involves is Online resources us replacing the for() loop For the purposes of this series, PinsSegs[7] = 11; in the loop() function with I’m going to assume that you an integer variable called are already familiar with funUsing arrays in conjunction with control constructs like for() iSeg – to which we assign damental concepts like voltloops is incredibly powerful and facilitates the writing of concise a random value. age, current and resistance. If code. For example, the latest iteration of our program that cycles The random values are not, you might want to start through all the display segments requires only 27 lines of code. provided by another of the by perusing and pondering Arduino IDE’s suite of prea short series of articles I defined functions, which What’s that for? penned on these very topics is, not surprisingly, called As we see in Listing 2, we are using two for() loops – one – see: https://bit.ly/3EguiJh random(). This function in our setup() function to define all of the pins in our array Similarly, I’ll assume you accepts two ‘arguments’ (for to be of type OUTPUT, and the other in our loop() function are no stranger to solderless the moment you may think to turn each segment on and off in turn. breadboards. Having said of these as parameters) that Let’s consider these in a little more detail, starting with the this, even if you’ve used these specify minimum and maxifact that a for() loop is a flow control statement that allows little scamps before, there are mum values for the random a block of code to be executed iteratively (repeatedly). This some aspects to them that can number to be generated. (If statement has two parts: a header that specifies and controls trap the unwary, so may I sugonly one argument is specithe iteration, and a body that is executed once per iteration. gest you feast your orbs on a fied, this is taken to be the The general form of a for() loop is as follows: column I wrote just for you – see: https://bit.ly/3NZ70uF Last, but not least, you will Cool bean Max Maxfield (Hawaiian shirt, on the right) is emperor of all he find a treasure trove of resourcsurveys at CliveMaxfield.com – the go-to site for the latest and greatest es at the Arduino.cc website, in technological geekdom. including example programs and reference documentation. Comments or questions? Email Max at: max<at>CliveMaxfield.com 66 Practical Electronics | February | 2023 maximum value and the minimum value will default to 0.) It’s important to note that the minimum value is inclusive (ie, it will be included in the set of possible values) while the maximum value is exclusive (ie, it will be excluded from the set of possible values). What does this mean in practice? Well, on Line 18 in Listing 3 we call random(0, NUM_SEGS). Remembering that we’ve defined NUM_SEGS as being 8, this means we are effectively calling random(0, 8), which will generate random numbers in the range 0 to 7. Since our PinsSegs[] array has eight elements numbered 0 to 7, everything works out just the way we want (and that’s not something you tend to hear as often as you might wish). Use the Arduino’s IDE to capture this latest incarnation of our code and upload it into your Arduino Uno. Now, feast your orbs on the display’s segments randomly turning on and off. Observe that the display sometimes pauses on a particular segment. Do you have any idea why this is happening? In fact, this occurs when the newly generated random number is the same as the old one because we haven’t (yet) included a test to ensure this circumstance doesn’t occur. JTAG Connector Plugs Directly into PCB!! No Header! No Brainer! What? Homework? There’s so much more I wanted to talk about in this column, but I think there’s more than enough here to keep you busy for a while. What would be useful while we wait for Part 3 is for you to think about what segments we need to activate to represent the digits 0 through 9 (we could create a 1 by lighting segments B and C, for example). Perhaps you could create a table of digits and corresponding segments. I’m sure I need not mention this (of course, I will anyway), but this table would be something you could record in your logbook. Until next time, as always, I welcome your insightful comments, perspicacious questions and sagacious suggestions. Our patented range of Plug-of-Nails™ spring-pin cables plug directly into a tiny footprint of pads and locating holes in your PCB, eliminating the need for a mating header. Save Cost & Space on Every PCB!! Solutions for: PIC . dsPIC . ARM . MSP430 . Atmel . Generic JTAG . Altera Xilinx . BDM . C2000 . SPY-BI-WIRE . SPI / IIC . Altium Mini-HDMI . & More www.PlugOfNails.com Tag-Connector footprints as small as 0.02 sq. inch (0.13 sq cm) STEWART OF READING 17A King Street, Mortimer, near Reading, RG7 3RS Telephone: 0118 933 1111 Fax: 0118 933 2375 USED ELECTRONIC TEST EQUIPMENT Check website www.stewart-of-reading.co.uk Fluke/Philips PM3092 Oscilloscope 2+2 Channel 200MHz Delay TB, Autoset etc – £250 LAMBDA GENESYS LAMBDA GENESYS IFR 2025 IFR 2948B IFR 6843 R&S APN62 Agilent 8712ET HP8903A/B HP8757D HP3325A HP3561A HP6032A HP6622A HP6624A HP6632B HP6644A HP6654A HP8341A HP83630A HP83624A HP8484A HP8560E HP8563A HP8566B HP8662A Marconi 2022E Marconi 2024 Marconi 2030 Marconi 2023A PSU GEN100-15 100V 15A Boxed As New £400 PSU GEN50-30 50V 30A £400 Signal Generator 9kHz – 2.51GHz Opt 04/11 £900 Communication Service Monitor Opts 03/25 Avionics POA Microwave Systems Analyser 10MHz – 20GHz POA Syn Function Generator 1Hz – 260kHz £295 RF Network Analyser 300kHz – 1300MHz POA Audio Analyser £750 – £950 Scaler Network Analyser POA Synthesised Function Generator £195 Dynamic Signal Analyser £650 PSU 0-60V 0-50A 1000W £750 PSU 0-20V 4A Twice or 0-50V 2A Twice £350 PSU 4 Outputs £400 PSU 0-20V 0-5A £195 PSU 0-60V 3.5A £400 PSU 0-60V 0-9A £500 Synthesised Sweep Generator 10MHz – 20GHz £2,000 Synthesised Sweeper 10MHz – 26.5 GHz POA Synthesised Sweeper 2 – 20GHz POA Power Sensor 0.01-18GHz 3nW-10µW £75 Spectrum Analyser Synthesised 30Hz – 2.9GHz £1,750 Spectrum Analyser Synthesised 9kHz – 22GHz £2,250 Spectrum Analsyer 100Hz – 22GHz £1,200 RF Generator 10kHz – 1280MHz £750 Synthesised AM/FM Signal Generator 10kHz – 1.01GHz £325 Synthesised Signal Generator 9kHz – 2.4GHz £800 Synthesised Signal Generator 10kHz – 1.35GHz £750 Signal Generator 9kHz – 1.2GHz £700 HP/Agilent HP 34401A Digital Multimeter 6½ Digit £325 – £375 HP 54600B Oscilloscope Analogue/Digital Dual Trace 100MHz Only £75, with accessories £125 (ALL PRICES PLUS CARRIAGE & VAT) Please check availability before ordering or calling in HP33120A HP53131A HP53131A Audio Precision Datron 4708 Druck DPI 515 Datron 1081 ENI 325LA Keithley 228 Time 9818 Practical Electronics | February | 2023 Marconi 2305 Marconi 2440 Marconi 2945/A/B Marconi 2955 Marconi 2955A Marconi 2955B Marconi 6200 Marconi 6200A Marconi 6200B Marconi 6960B Tektronix TDS3052B Tektronix TDS3032 Tektronix TDS3012 Tektronix 2430A Tektronix 2465B Farnell AP60/50 Farnell XA35/2T Farnell AP100-90 Farnell LF1 Racal 1991 Racal 2101 Racal 9300 Racal 9300B Solartron 7150/PLUS Solatron 1253 Solartron SI 1255 Tasakago TM035-2 Thurlby PL320QMD Thurlby TG210 Modulation Meter £250 Counter 20GHz £295 Communications Test Set Various Options POA Radio Communications Test Set £595 Radio Communications Test Set £725 Radio Communications Test Set £800 Microwave Test Set £1,500 Microwave Test Set 10MHz – 20GHz £1,950 Microwave Test Set £2,300 Power Meter with 6910 sensor £295 Oscilloscope 500MHz 2.5GS/s £1,250 Oscilloscope 300MHz 2.5GS/s £995 Oscilloscope 2 Channel 100MHz 1.25GS/s £450 Oscilloscope Dual Trace 150MHz 100MS/s £350 Oscilloscope 4 Channel 400MHz £600 PSU 0-60V 0-50A 1kW Switch Mode £300 PSU 0-35V 0-2A Twice Digital £75 Power Supply 100V 90A £900 Sine/Sq Oscillator 10Hz – 1MHz £45 Counter/Timer 160MHz 9 Digit £150 Counter 20GHz LED £295 True RMS Millivoltmeter 5Hz – 20MHz etc £45 As 9300 £75 6½ Digit DMM True RMS IEEE £65/£75 Gain Phase Analyser 1mHz – 20kHz £600 HF Frequency Response Analyser POA PSU 0-35V 0-2A 2 Meters £30 PSU 0-30V 0-2A Twice £160 – £200 Function Generator 0.002-2MHz TTL etc Kenwood Badged £65 Function Generator 100 microHz – 15MHz Universal Counter 3GHz Boxed unused Universal Counter 225MHz SYS2712 Audio Analyser – in original box Autocal Multifunction Standard Pressure Calibrator/Controller Autocal Standards Multimeter RF Power Amplifier 250kHz – 150MHz 25W 50dB Voltage/Current Source DC Current & Voltage Calibrator £350 £600 £350 POA POA £400 POA POA POA POA Marconi 2955B Radio Communications Test Set – £800 67