/ examples / 74hc595_8_led.py
74hc595_8_led.py
 1  import time
 2  import board
 3  import digitalio
 4  import adafruit_74hc595
 5  
 6  latch_pin = digitalio.DigitalInOut(board.D5)
 7  sr = adafruit_74hc595.ShiftRegister74HC595(board.SPI(), latch_pin)
 8  
 9  # Create the pin objects in a list
10  pins = [sr.get_pin(n) for n in range(8)]
11  
12  while True:
13      for _ in range(2):  # Run the chase animation twice
14          for enabled_pin in range(len(pins)):
15              for pin_number, pin in enumerate(pins):
16                  if pin_number == enabled_pin:
17                      pin.value = True
18                  else:
19                      pin.value = False
20                  time.sleep(0.01)
21      for _ in range(3):  # Run the blink animation three times
22          for pin in pins:
23              pin.value = True
24          time.sleep(0.5)
25          for pin in pins:
26              pin.value = False
27          time.sleep(0.5)