EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #187 background imageLoading...
Page #187 background image
187
Chapter 17 74HC595 & LEDBar Graph
www.freenove.com
support@freenove.com
49
50
51
52
53
54
print ('Program is starting...')
setup()
try:
loop()
e xcept KeyboardInterrupt:
destroy()
In the code, we define a shiftOut() function, which is used to output value with bit in order. And where the
dPin for the data pin, cPin for the clock and order for the priority bit flag (high or low). This function conforms
to the operation mode of 74HC595. LSBFIRST and MSBFIRST are two different flow directions.
def shiftOut(dPin,cPin,order,val):
for i in range(0,8):
GPIO.output(cPin,GPIO.LOW);
if(order == LSBFIRST):
GPIO.output(dPin,(0x01&(val>>i)==0x01) and GPIO.HIGH or GPIO.LOW)
elif(order == MSBFIRST):
GPIO.output(dPin,(0x80&(val<<i)==0x80) and GPIO.HIGH or GPIO.LOW)
GPIO.output(cPin,GPIO.HIGH);
In the loop() function, we use two forcycle to achieve the target. First, define a variable x=0x01, binary
00000001. When it is transferred to the output port of 74HC595, the low bit outputs high level, then a LED is
turned on. Next, x is shifted one bit, when x is transferred to the output port of 74HC595 once again, the LED
turned on will be shifted. Repeat the operation, the effect of flowing water light will be formed. If the direction
of the shift operation for x is different, the flowing direction is different.
def loop():
w hile Tr ue:
x= 0x01
for i in range(0,8):
GPIO.output(latchPin,GPIO.LOW) #Output low level to latchPin
shiftOut(dataPin,clockPin,LSBFIRST,x)#Send serial data to 74HC595
GPIO.output(latchPin,GPIO.HIGH)#Output high level to latchPin, and 74HC595
will update the data to the parallel output port.
x<<=1# make the variable move one bit to left once, then the bright LED move
one step to the left once.
time.sleep(0.1)
x= 0x80
for i in range(0,8):
GPIO.output(latchPin,GPIO.LOW)
shiftOut(dataPin,clockPin,LSBFIRST,x)
GPIO.output(latchPin,GPIO.HIGH)
x>>=1
time.sleep(0.1)

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish