User Manual
94
def hc595_shift(dat): # Shift the data to 74HC595
for bit in range(0, 8):
GPIO.output(SDI, 0x80 & (dat << bit)) # Assign dat data to SDI pins of HC595 by
bits
GPIO.output(SRCLK, GPIO.HIGH) # Every SRCLK adds one, the shift register moves
one bit.
time.sleep(0.001)
GPIO.output(SRCLK, GPIO.LOW)
GPIO.output(RCLK, GPIO.HIGH) # Everytime RCLK adds one, the HC595 updates output.
time.sleep(0.001)
GPIO.output(RCLK, GPIO.LOW)
leds = ['-', '-', '-', '-', '-', '-', '-', '-'] # the array storing the LED state, used
for command line printing.
while True:
# Change LED status from mode
print " mode"
for onoff in mode: # Assign value to variable onoff by mode[] list
hc595_shift(onoff)
leds[mode.index(onoff)] = 1 # Show which led is on
print leds
time.sleep(sleeptime)
leds[mode.index(onoff)] = '-' # Show the led is off
# for loops in later part work similarly, lighting up LED by list.
Input a 2-bit hexadecimal parameter dat via hc595_in(dat) to control 8 LEDs state, and
hc595_out() will output state to 8 LEDs. In While True, the for loop will shift the LED blinking
list to the hc595_in(dat) function, thus we can see the LED light flow ing.
SunFounder