1、编程实现8个7段数码管同时显示相同的数字0-9,并每隔1秒变换一次; 2、编程实现8个7段数码管左移轮流显示数字0-9,A-F。
时间: 2024-04-06 20:29:29 浏览: 52
51单片机使用8个数码管中的一个数码管,循环显示数字0~9,到9回0,数字变化的时间间隔为1s。
5星 · 资源好评率100%
1、
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# 7段数码管对应的引脚
segments = (14, 15, 18, 23, 24, 25, 8)
# 数字对应的段码
digits = {
0: (1, 1, 1, 1, 1, 1, 0),
1: (0, 1, 1, 0, 0, 0, 0),
2: (1, 1, 0, 1, 1, 0, 1),
3: (1, 1, 1, 1, 0, 0, 1),
4: (0, 1, 1, 0, 0, 1, 1),
5: (1, 0, 1, 1, 0, 1, 1),
6: (1, 0, 1, 1, 1, 1, 1),
7: (1, 1, 1, 0, 0, 0, 0),
8: (1, 1, 1, 1, 1, 1, 1),
9: (1, 1, 1, 1, 0, 1, 1)
}
# 初始化引脚
for segment in segments:
GPIO.setup(segment, GPIO.OUT)
GPIO.output(segment, 0)
# 显示数字
def display_number(number):
for digit in range(0, 7):
segment = segments[digit]
GPIO.output(segment, digits[number][digit])
# 循环显示
while True:
for number in range(0, 10):
for i in range(0, 8):
display_number(number)
time.sleep(1)
```
2、
```python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# 7段数码管对应的引脚
segments = (14, 15, 18, 23, 24, 25, 8)
# 数字对应的段码
digits = {
0: (1, 1, 1, 1, 1, 1, 0),
1: (0, 1, 1, 0, 0, 0, 0),
2: (1, 1, 0, 1, 1, 0, 1),
3: (1, 1, 1, 1, 0, 0, 1),
4: (0, 1, 1, 0, 0, 1, 1),
5: (1, 0, 1, 1, 0, 1, 1),
6: (1, 0, 1, 1, 1, 1, 1),
7: (1, 1, 1, 0, 0, 0, 0),
8: (1, 1, 1, 1, 1, 1, 1),
9: (1, 1, 1, 1, 0, 1, 1),
10: (1, 1, 1, 0, 1, 1, 1),
11: (0, 0, 1, 1, 1, 1, 1),
12: (1, 0, 0, 1, 1, 1, 0),
13: (0, 1, 1, 1, 1, 0, 1),
14: (1, 0, 0, 1, 1, 1, 1),
15: (1, 0, 0, 0, 1, 1, 1)
}
# 初始化引脚
for segment in segments:
GPIO.setup(segment, GPIO.OUT)
GPIO.output(segment, 0)
# 显示数字和字母
def display_digit(digit):
for i in range(0, 7):
segment = segments[i]
GPIO.output(segment, digits[digit][i])
# 循环显示
while True:
for i in range(0, 16):
for j in range(0, 8):
display_digit(i + j)
time.sleep(0.1)
```
阅读全文