EasyManua.ls Logo

Freenove Ultimate Starter Kit - Page 183

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
Loading...
183
Chapter 17 74HC595 & LEDBar Graph
www.freenove.com
support@freenove.com
Code
In this project, make a flowing water light with 74HC595 to learn its usage.
C 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 C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/17.1.1_LightWater02
2. Use following command to compile “LightWater02.cand generate executable file “LightWater02”.
gcc LightWater02.c -o LightWater02 -lwiringPi
3. Then run the generated file “LightWater02”.
sudo ./LightWater02
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
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
#include <wiringPi.h>
#include <stdio.h>
#include <wiringShift.h>
#define dataPin 0 //DS Pin of 74HC595(Pin14)
#define latchPin 2 //ST_CP Pin of 74HC595(Pin12)
#define clockPin 3 //SH_CP Pin of 74HC595(Pin11)
void _shiftOut(int dPin,int cPin,int order,int val){
int i;
for(i = 0; i < 8; i++ ){
digitalWrite(cPin,LOW);
if(order == LSBFIRST){
digitalWrite(dPin,((0x01&(val>>i)) == 0x01) ? HIGH : LOW);
delayMicroseconds(10);
}
else {//if(order == MSBFIRST){
digitalWrite(dPin,((0x80&(val<<i)) == 0x80) ? HIGH : LOW);
delayMicroseconds(10);
}
digitalWrite(cPin,HIGH);
delayMicroseconds(10);
}
}
int main( void)
{
int i;
unsigned char x;

Table of Contents