动手学树莓派Python篇第7章:LED灯原来是这样点亮的

SAKSHAT提供的LED使用方法

当前SAKSHAT为我们提供的方法参考:http://wiki.nxez.com/saks:sdk:libraries:led74hc595

这里就直接摘录了,以下是创百科的内容:
74HC595 芯片驱动下的 LED 灯组类,控制一组 LED 工作。 方法

init(self, pins, real_true=GPIO.HIGH)

初始化对象,设置引脚和触发电平(高电平或低电平触发)。pins 为 IO 引脚数组。

ic(self)

返回当前驱动数码管的IC对象。

is_on(self, index)

返回当前 LED 的工作状态。true 或 false。index 为 LED 编号,从 0 开始。

row_status(self)

返回当前 LED 灯组的工作状态的数组。

on(self)

设置 LED 灯组为全部点亮状态。

off(self)

设置 LED 灯组为全部熄灭状态。

on_for_index(self, index)

设置当前 LED 灯组的第 index+1 个 LED 的状态为点亮。index 为 LED 编号,从 0 开始。

off_for_index(self, index)

设置当前 LED 灯组的第 index+1 个 LED 的状态为熄灭。index 为 LED 编号,从 0 开始。

set_row(self, status)

设置当前 LED 灯组的点亮状态。status 为布尔型数组。status 中的元素也可以为 None,表示不改变该元素位置的 LED 状态。

#点亮所有LED灯
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        #点亮所有LED灯
        SAKS.ledrow.on()
         
    except KeyboardInterrupt:
        print("任务被终止了")
#熄灭所有LED灯
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        #熄灭所有LED灯
        SAKS.ledrow.off()
         
    except KeyboardInterrupt:
        print("任务被终止了")
#返回当前LED灯组状态。
import time
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
led_status = []
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        #点亮所有灯并输出所有灯状态
        for i in range(0, 8):
            SAKS.ledrow.on_for_index(i)
        led_status = SAKS.ledrow.row_status
        print("点亮所有灯状态" + str(led_status))
         
        time.sleep(5)
         
        #关闭所有灯并输出等状态
        for i in range(0, 8):
            SAKS.ledrow.off_for_index(i)
        led_status = SAKS.ledrow.row_status
        print("关闭所有灯状态" + str(led_status))
         
        time.sleep(5)
         
        #熄灭所有LED灯
        SAKS.ledrow.off()
         
        #间隔点亮LED灯模式1
        for i in range(0, 8, 2):
            SAKS.ledrow.on_for_index(i)
        led_status = SAKS.ledrow.row_status
        print("间隔点亮LED灯模式1" + str(led_status))
         
        time.sleep(5)
         
        #熄灭所有LED灯
        SAKS.ledrow.off()
         
        #间隔点亮LED灯模式2
        for i in range(1, 8, 2):
            SAKS.ledrow.on_for_index(i)
        led_status = SAKS.ledrow.row_status
        print("间隔点亮LED灯模式2" + str(led_status))
         
    except KeyboardInterrupt:
        print("任务被终止了")
#返回当前LED单个灯状态。
import time
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
led_status = []
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        #熄灭所有LED灯
        SAKS.ledrow.off()
         
        #关闭所有灯并输出等状态
        for i in range(0, 8, 2):
            SAKS.ledrow.on_for_index(i)
        led_status = SAKS.ledrow.row_status
        print("关闭所有灯状态" + str(led_status))
         
        for i in range(0, 8):
            led_one_status = SAKS.ledrow.is_on(i)
            print("第" + str(i) + "个LED灯状态为" + str(led_one_status))
               
    except KeyboardInterrupt:
        print("任务被终止了")
#逐一点亮LED灯,然后逐一熄灭LED灯
import time
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        for i in range(0, 8):
            SAKS.ledrow.on_for_index(i)
            time.sleep(1)
             
        for i in range(0, 8):
            SAKS.ledrow.off_for_index(i)
            time.sleep(1)
         
    except KeyboardInterrupt:
        print("任务被终止了")
#设置LED灯族状态
import time
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        SAKS.ledrow.set_row([True, False, True, False, True, False, True, False])
 
        time.sleep(5)
 
        SAKS.ledrow.set_row([None, True, None, True, None, None, None, None])
 
        time.sleep(5)
         
        SAKS.ledrow.set_row([None, None, None, None, None, True, None, True])
         
        time.sleep(5)
         
        SAKS.ledrow.set_row([False, None, False, None, False, None, False, None])
         
        time.sleep(5)
         
        SAKS.ledrow.set_row([False, False, False, False, False, False, False, False])
         
    except KeyboardInterrupt:
        print("任务被终止了")
#流水灯走起
import time
from sakshat import SAKSHAT
from sakspins import SAKSPins as PINS
 
if __name__ == "__main__":
    try:
        #Declare the SAKS Board
        SAKS = SAKSHAT()
         
        while True:         
            for i in range(0, 8):
                SAKS.ledrow.on_for_index(i)
                time.sleep(0.1)
                SAKS.ledrow.off_for_index(i)
    except KeyboardInterrupt:
        print("任务被终止了")

课程 bilibili 视频地址:https://www.bilibili.com/video/av71878718/?p=18

- 本文内容来自网络,如有侵权,请联系本站处理。

2022-12   阅读(108)   评论(0)
 标签: 编程

涨知识
SPI

SPI是串行外设接口(Serial Peripheral Interface)的缩写,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用四根线,节约了芯片的管脚。

评论:
相关文章
C 语言怎么可能被淘汰呢?

学习 C 是宝贵的经验,非常值得。即便不作为第一门语言,也应该作为第二、第三或第四门编程语言进行学习。C 有很多优点,但也有一些缺点。至少学习C 编程没有任何损失。所以,请给自己一个机会,尝试一下,也许你会像我一样爱上它。



App Inventor 编程实例及指南-序言

App Inventor 编程实例及指南



【ESP32 C++教程】Unit9-2:文件系统应用

本小节是一个Web服务结合SD卡文件系统的应用示例。


Scratch 3.0 介绍

Scratch 3.0采用了HTML5和JavaScript技术来编写,支持所有的现代浏览器和WebGL,能够跨平台使用。 让写程式更容易入门。


CCF中学生计算机程序设计能力等级评价等级标准

CCF于2013年设立《青少年计算机程序设计评价标准》课题,于2014年7月形成评价体系并予以发布。凡参加NOI系列活动的选手均可参加等级评价。


Blockly 工作区域

将Blockly放到网页中的最简单方法是将其注入到空的“div”标签中。


Arduino IDE中使用文件夹为项目组织源文件

本文介绍了如何在ArduinoIDE中利用文件夹结构更好地组织源文件和头文件,以提高代码清晰度和维护性。


machine.ADC – 模数转换

ADC 类为模数转换器提供了一个接口,并表示一个端点,可以对连续电压进行采样并将其转换为离散值。