74HC595 接腳位的圖片說明:
Source: pimoroni.com
腳位編號 | 名稱 | 說明 |
1-7, 15 | Q0 ~ Q7 | 輸出腳位 |
8 | GND | 接地 |
9 | Q7’ | 序列輸出 (Serial Out) |
10 | MR | Master Reset, 清除所有資料, 低電位有效 |
11 | SH_CP | SHift register clock pin (Clock Pin) |
12 | ST_CP | STorage register clock pin (Latch Pin) |
13 | OE | Output Enable, 允許輸出,低電位有效 (Active low) |
14 | DS | 序列資料輸入 (Serial data input) |
16 | Vcc | 供應電壓 |
電子零件:
Python 程式碼:
#!/usr/bin/python
import RPi.GPIO as gpio
import time
DS = 5 # Serial Data
SHCP = 27 # Clock
STCP = 17 # Latch
gpio.setmode(gpio.BCM)
gpio.setup(DS, gpio.OUT)
gpio.setup(SHCP, gpio.OUT)
gpio.setup(STCP, gpio.OUT)
def shiftout(byte):
gpio.output(STCP, 0)
b = ''
for x in range(8):
bit = ((byte >> x) & 1)
b = b + str(bit)
gpio.output(DS, bit)
gpio.output(SHCP, 1)
gpio.output(SHCP, 0)
print(b[::-1])
gpio.output(STCP, 1)
for x in range(256):
shiftout(x)
time.sleep(0.15)
time.sleep(3)
gpio.cleanup()
實驗短片:
實驗短片:
沒有留言:
張貼留言