gpiozero API All In One
gpiozero API All In One
Python & Raspberry Pi
# gpiozero 1.6.2 / Released: Mar 19, 2021
$ pip install gpiozero
$ pip3 install gpiozero
https://pypi.org/project/gpiozero/
https://github.com/gpiozero/gpiozero
API docs
https://gpiozero.readthedocs.io/en/stable/
from gpiozero import LED
from gpiozero import RGBLED
from gpiozero import Button
from gpiozero import OutputDevice, MotionSensor, LightSensor
from gpiozero.tools import booleanized, all_values
以下几行都是等价的:
>>> led = LED(17)
>>> led = LED("GPIO17")
>>> led = LED("BCM17")
>>> led = LED("BOARD11")
>>> led = LED("WPI0")
>>> led = LED("J8:11")
https://gpiozero.readthedocs.io/en/stable/recipes.html#
demos
#!/usr/bin/env python3
# coding: utf8
from gpiozero import RGBLED
from time import sleep
led = RGBLED(17, 22, 27)
for r in range(2):
for g in range(2):
for b in range(2):
led.color = (r, g, b)
sleep(1)
# 在树莓派上运行脚本即可完成小灯每隔1秒的闪烁。
"""
https://youtu.be/t3SFYgN2WEc?t=754
"""
#!/usr/bin/env python3
# coding: utf8
# from gpiozero import LED
from gpiozero import RGBLED
from colorzero import Color
from time import sleep
# RBG
# RED = LED(17)
# GREEN = LED(27)
# BLUE = LED(22)
# RED.on()
# RED.off()
# GREEN.on()
# GREEN.off()
# BLUE.on()
# BLUE.off()
# RED.close()
# GREEN.close()
# BLUE.close()
led = RGBLED(17, 22, 27)
while True:
# 0 ~ 1 ??? 0 ~ 255
# led.color = (0, 1, 0)
led.color = Color("pink")
sleep(1)
# for r in range(2):
# for g in range(2):
# for b in range(2):
# led.color = (r, g, b)
# sleep(1)
# 在树莓派上运行脚本即可完成小灯每隔1秒的闪烁。
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17397502.html
未经授权禁止转载,违者必究!