Create a file called Display.py
the variable toDisplay sets what you want to show in your display.
Delay is the time every single digit stays on. So, it also depends on the refresh rate for the overall display. This is an important variable. A too low delay means that Raspberry PI could not be able to disable/enable GPIOs so fast, thus resulting in all segments in all digits appearing on. A too high delay means that refresh rate is affected, resulting in a blinking effect for display digits (with the persistence of vision resulting compromised).
Lowering this can make debugging easier as it allows for you to see the program progressing through each stage.
The following section defines what Raspberry PI pins we are going to use. We will use BCM naming convention. Please refer to Raspberry PI Pinout for physical to BCM relations
digitDP refers to the pin of the dot
Then the pins are looped through and set as output pins for their different locations.
Warnings are enabled/disabled because the script leaves pins active on close, and when running it again it will through usage errors
Then an array is made to map out the numbers (so that arrSeg[0] shows 0, arrSeg[1] shows 1, etc):
With an array so composed, the showDsiplay function takes charge to display all 4 digits. This uses a for cycle with 4 steps. Each step enables a digit by putting its selector to 1 (HIGH).
All of the confusing string manipulation code is there to handle inputs such as “4.2.7.0” and display the dots properly.
Then the two main functions come. As you can remember, we defined what to display as a string in toDisplay variable. splitToDisplay function splits this string in an array of 4 elements so that each element is a simple number (or space). Also, dots are added to the element that the dot is following.
Now that numbers can be output, the value being displayed needs to be able to be updated. In order to be able to display the changed inputs we need to set a default character, in this case 0, so that the display can display a non 4-digit number.
This is done in the output function which will be called by the keypad Program.
In order to test the display several numbers should be put into the following function:
If the display doesn’t output the correct numbers make sure that none of the resistors are touching and that all of the cables are plugged into the correct pins.
If this continues to not work bumping up the delay variable to around .5 can make it easier to figure out what might be wrong.