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 #185 background imageLoading...
Page #185 background image
185
Chapter 17 74HC595 & LEDBar Graph
www.freenove.com
support@freenove.com
}
In second for” cycle, the situation is the same. The difference is that x is shift from 0x80 to right in order.
<< operator
"<<" is the left shift operator, which can make all bits of 1 byte shift by several bits to the left (high) direction
and add 0 on the right (low). For example, shift binary 00000001 by 1 bit to left:
byte x = 1 << 1;
0
0
0
0
0
0
0
1
0
The result of x is 2binary 00000010.
0
0
0
0
0
0
1
0
There is another similar operator" >>". For example, shift binary 00000001 by 1 bit to right:
byte x = 1 >> 1;
0
0
0
0
0
0
0
0
1
The result of x is 000000000.
0
0
0
0
0
0
0
0
X <<= 1 is equivalent to x = x << 1 and x >>= 1 is equivalent to x = x >> 1
About shift function
uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ;
This is used to shift an 8-bit data value in with the data appearing on the dPin and the clock being sent out
on the cPin. Order is either LSBFIRST or MSBFIRST. The data is sampled after the cPin goes high. (So cPin
high, sample data, cPin low, repeat for 8 bits) The 8-bit value is returned by the function.
void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ;
void _shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ;
This is used to shift an 8-bit data value out with the data being sent out on dPin and the clock being sent
out on the cPin. order is as above. Data is clocked out on the rising or falling edge - ie. dPin is set, then
cPin is taken high then low - repeated for the 8 bits.
For more details about shift function, please refer to: http://wiringpi.com/reference/shift-library/
Python Code 17.1.1 LightWater02
First observe the project result, and then analyze the code.
1. Use cd command to enter 17.1.1_LightWater02 directory of Python code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/Python_Code/17.1.1_LightWater02
2. Use python command to execute python code “LightWater02.py”.
python LightWater02.py
After the program is executed, LEDBar Graph begin to display flowing water light from left to right, then from
right to left.
The following is the program code:
1
2
3
4
im port RPi. GPIO as GPIO
im port time
# Defines the data bit that is transmitted preferentially in the shiftOut function.
LSBFIRST = 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