94
For C language users:
Step 2: Get into the folder of the code.
cd
/
home
/
pi
/
SunFounder_Super_Kit_V3.0_for_Raspberry_Pi
/
C
Step 3: Compile
make 14_segment
Step 4: Run the executable file above.
sudo
./
14_segment
Code Explanation
unsigned char SegCode[17] =
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x80};
// display array from 0 to F.
void init(void){}
// Initialize the function, set ds, st_cp, sh_cp three pins to low
level, and the initial state as 0.
void hc595_shift(unsigned char dat){
int i;
for(i=0;i<8;i++){
digitalWrite(SDI, 0x80 & (dat << i));
// Assign the dat data to SDI(DS) by
bits. Here we assume dat=0x3f(0011 1111, when i=0, 0x3f will shift right(<<) 0 bits,
0x3f & 0x80 = 1000 0000,
digitalWrite(SRCLK, 1);
// SH_CP will convert from low to high, and generate a
rising edge pulse, then shift the DS date to shift register.
delay(1);
digitalWrite(SRCLK, 0);
}
// to assign 8 bit value to 74HC595
’s
shift register
digitalWrite(RCLK, 1);
// ST_CP converts from low to high and generate a rising
edge, then shift data from shift register to storage register.
delay(1);
digitalWrite(RCLK, 0);
}
// Transfer data in shift register to data register to update the displayed data.
For Python users:
Step 2: Get into the folder of the code.
cd
/
home
/
pi
/
SunFounder_Super_Kit_V3.0_for_Raspberry_Pi
/
Python
Step 3: Run
sudo
python
14_segment.py
Code Explanation
# Define a segment code from 0 to F in Hexadecimal
# Commen cathode
Содержание Super Kit 3.0
Страница 7: ...4 22 RGB LED 1 23 LED red 8 24 LED white 4 25 LED green 4 26 LED yellow 4 27 NPN Transistor S8050 2 ...
Страница 30: ...27 Also we have drawn a table of the corresponding BCM wiringPi and Name of each pins ...
Страница 78: ...75 Now pull the slide and you can see the two LEDs light up alternately ...