the_software_build_and_test
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
the_software_build_and_test [2017/01/22 17:01] – walkeradmin | the_software_build_and_test [2023/03/09 22:35] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 19: | Line 19: | ||
- My 7 Segment LED is Common Anode, the original code is for common cathode. | - My 7 Segment LED is Common Anode, the original code is for common cathode. | ||
- My 7 Segment LED has a time separator and full stops (so is 8 segments) the original does not. | - My 7 Segment LED has a time separator and full stops (so is 8 segments) the original does not. | ||
+ | - I used different GPIO lines. | ||
+ | |||
+ | ---- | ||
+ | ==== Working Clock Code ==== | ||
\\ | \\ | ||
- | \\ | + | This is the final version of code that was used. It has the support for the flashing dots time separator. If cutting and pasting isn't working well for you, download the python file {{ : |
- | <file> | + | <sxh [py][; options for SyntaxHighlighter]> |
+ | #! / | ||
+ | # Python Script to run a 7 Segment Common Anode LED as a clock. | ||
+ | # Version 1.0 | ||
import RPi.GPIO as GPIO | import RPi.GPIO as GPIO | ||
import time | import time | ||
+ | |||
+ | #Define numbering system for the IO pins Raspberry Pi | ||
GPIO.setmode(GPIO.BCM) | GPIO.setmode(GPIO.BCM) | ||
- | # GPIO pins used to display 7 segments | + | # Define |
gpioSegments = (5, | gpioSegments = (5, | ||
- | + | # 7seg_segment_pins (11, | |
- | for segment in gpioSegments: | + | # Setup channels for output and set initial values |
- | GPIO.setup(segment, | + | for segment in (gpioSegments): |
- | GPIO.output(segment, | + | GPIO.setup(segment, |
- | + | GPIO.output(segment, | |
- | # GPIO pins used to select digit 0-3 | + | |
+ | # Define | ||
gpioDigits = (18, | gpioDigits = (18, | ||
- | + | # Pins (12,9,8,6) select digits 0-3 respectively reading LTR on display | |
- | for digit in gpioDigits: | + | # Setup channels for output and set initial values |
- | GPIO.setup(digit, | + | for digit in (gpioDigits): |
- | GPIO.output(digit, | + | GPIO.setup(digit, |
+ | GPIO.output(digit, | ||
+ | |||
+ | #Define flags for comtrol of Colon separator on display | ||
+ | colon_visible=True | ||
+ | colon_counter=0 | ||
- | numbers = {' | + | #Define segment arrays for each number to be displayed |
+ | numbers = { | ||
+ | ' | ||
' | ' | ||
' | ' | ||
Line 51: | Line 68: | ||
' | ' | ||
' ': | ' ': | ||
- | | + | |
+ | #Cycle through each digit and its segments | ||
try: | try: | ||
while True: | while True: | ||
- | | + | |
- | s = str(n).rjust(4) | + | |
for digit in range(4): | for digit in range(4): | ||
- | for loop in range(0, | + | #select |
- | GPIO.output(gpioSegments[loop], | + | |
- | | + | |
- | # GPIO.output(23, | + | |
- | #else: | + | |
- | # GPIO.output(23, | + | |
GPIO.output(gpioDigits[digit], | GPIO.output(gpioDigits[digit], | ||
+ | #set required segments on | ||
+ | for segment in range(0,8): | ||
+ | GPIO.output(gpioSegments[segment], | ||
+ | #check to see if we are on segment 3 of digit 2(LTR) | ||
+ | if ((digit==1) and (segment==2)): | ||
+ | #when colon counter gets to set value flip colon display mode between TRUE (visible) and False (NOT.visible) | ||
+ | if (colon_counter< | ||
+ | #count value not reached turn colon ON or OFF based on current setting of colon_visible | ||
+ | if colon_visible==True: | ||
+ | GPIO.output(13, | ||
+ | else: | ||
+ | GPIO.output(13, | ||
+ | #colon counter set value reached so flip colon display mode and reset colon counter | ||
+ | else: | ||
+ | colon_counter = 0 | ||
+ | colon_visible = not colon_visible | ||
+ | #display all selected segments for a short time | ||
time.sleep(0.005) | time.sleep(0.005) | ||
- | | + | #turn-off All segments |
+ | for segment in range(0, | ||
+ | GPIO.output(gpioSegments[segment], | ||
+ | #turn-off current digit selector pin | ||
+ | | ||
+ | #advance colon counter | ||
+ | colon_counter=colon_counter+1 | ||
finally: | finally: | ||
- | | + | |
- | </file> | + | </sxh> |
\\ | \\ | ||
\\ | \\ | ||
Line 74: | Line 109: | ||
---- | ---- | ||
\\ | \\ | ||
- | ==== Here is the orinial | + | ==== Here is the original |
- | \\ | + | <sxh [py][; options for SyntaxHighlighter]> |
- | <file> | + | |
# code modified, tweaked and tailored from code by bertwert | # code modified, tweaked and tailored from code by bertwert | ||
# on RPi forum thread topic 91796 | # on RPi forum thread topic 91796 | ||
Line 127: | Line 161: | ||
finally: | finally: | ||
GPIO.cleanup() | GPIO.cleanup() | ||
- | + | </sxh> | |
- | </file> | + |
the_software_build_and_test.1485104504.txt.gz · Last modified: 2023/03/09 22:35 (external edit)