89
AND operation. (0x80 >> i) is to implement the operation from left to right by bit, so
each time one of the eight bits in byte (0000 0001).
pulse(SRCLK);
// the shift register generates a rising edge pulse, and data in
DS will shift to the shift register.
}
// This part is to assign the data in byte to SDI(DS) by bits, thus when the shift
register generates a rising edge pulse, data in SDI(DS) will transfer to it by bits.
}
void init(void):
// Set DS, ST_CP, SH_CP as output, and low level as the initial state
for(i=0;i<8;i++){
SIPO(LED[i]);
// Assign the value in the LED[i] array to SDI(DS). When i=1,
LED[0]=0x01 shifts to the shift register.
pulse(RCLK);
// RCLK (ST_CP) generates a rising edge pulse, and the data of the
shift register is stored in the RCLK (ST_CP) storage register, and output at Q0-Q7.
delay(150);
}
After 8 cycles, Q0-Q7 will output 0x01 to 0x10 in sequence, that is to light up the
LEDs connected to Q0-Q7 in turn.
Sketch in later part not explained here is to light up 8 LEDs together, and dim them; then light
up LEDs connected to Q7-Q0 one by one, and all 8 LEDs light up, dim in the end. Thus, a
cycle completes. You can observe the LEDs’ state.
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
13_74HC595_LED.py
Code Explanation
LED0 = [0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80]
# Define some LED blinking
modes. Convert hexadecimal value to binary value will be more intuitionistic. For
instance, 0x01 is binary 00000001, meaning the last LED lighting up; 0x80 is binary
10000000, representing the first LED lighting up.
LED1 = [0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff]
# blink mode 1
LED2 = [0x01,0x05,0x15,0x55,0xb5,0xf5,0xfb,0xff]
# blink mode 2
LED3 = [0x02,0x03,0x0b,0x0f,0x2f,0x3f,0xbf,0xff]
# blink mode 3
# Shift the data to 74HC595
def hc595_shift(dat):
# Shift the data to 74HC595
for bit in range(0, 8):
Содержание 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 ...