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 #193 background imageLoading...
Page #193 background image
193
Chapter 18 74HC595 & 7-segment display.
www.freenove.com
support@freenove.com
If you want to display the decimal point, make the highest bit of each array become 0, which can be
implemented easily by num[i]&0x7f.
_shiftOut(dataPin,clockPin,MSBFIRST,num[i] & 0x7f);
Python Code 18.1.1 SevenSegmentDisplay
First observe the project result, and then analyze the code.
1. Use cd command to enter 18.1.1_SevenSegmentDisplay directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/18.1.1_SevenSegmentDisplay
2. Use python command to execute python code “SevenSegmentDisplay.py”.
python SevenSegmentDisplay.py
After the program is executed, SevenSegmentDisplay starts to display the character “0”- “F” successively.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
im port RPi. GPIO as GPIO
im port time
LSBFIRST = 1
MSBFIRST = 2
#define the pins connect to 74HC595
dataPin = 11 #DS Pin of 74HC595(Pin14)
latchPin = 13 #ST_CP Pin of 74HC595(Pin12)
clockPin = 15 #CH_CP Pin of 74HC595(Pin11)
#SevenSegmentDisplay display the character "0"- "F"successively
num = [0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e]
def setup():
GPIO. setmode(GPIO.BOARD) # Number GPIOs by its physical location
GPIO. setup(dataPin, GPIO. OUT)
GPIO. setup(latchPin, GPIO. OUT)
GPIO. setup(clockPin, GPIO. OUT)
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);
def loop():
w hile Tr ue:
for i in range(0,len(num)):
GPIO.output(latchPin,GPIO.LOW)
shiftOut(dataPin,clockPin,MSBFIRST,num[i])#Output the figures and the highest
level is transfered preferentially.

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