当前位置:网站首页>V831——IO口的使用
V831——IO口的使用
2022-07-16 11:43:00 【我与nano】
V831
前言
之前学习831的时候,io口总是出问题,后来更新了新的镜像,应该是官方把bug修复了
一、GPIO
GPIO, 全称 General-Purpose Input/Output(通用输入输出),是一种软件运行期间能够动态配置和控制的通用引脚。所有的 GPIO 在上电后的初始状态都是输入模式,可以控制电平的输出和获取外设的电平变化。
二、蜂鸣器

过控制 GPIO 进行高低电平的输出,使用之前需要加载对应板子的 GPIO 配置。通过查看开发板管脚定义图,确定所使用的 IO 管脚号,例如下面使用的是 MaixII-Dock 的 GPIO PH6 管脚,则需要使用 gpio.gpio(6, “H”, 1),进行定义,完整代码如下:
import time
from maix import gpio
beep = gpio.gpio(6, "H", 1)
while True:
beep.set_value(0)
print(beep.get_value())
time.sleep(0.5)
beep.set_value(1)
print(beep.get_value())
time.sleep(0.5)
beep.release()
然后你就可以听到蜂鸣器响了,之前也是一模一样的代码,可它就是不响。
三、按键
将 GPIO 设置成输入模式,才能获取板子的电平变化。需要在 GPIO 实例化的时候添加多一个参数,来设置 GPIO 的模式。
key = gpio.gpio(6, "H", 1, line_mode = 2)#2 为设置成输入模式,该参数默认为 1,即输出模式
GPIO 使用结束之后需要将其释放,否则会处于占用状态,通过 gpio.release() 释放 GPIO 或者使用一个类封装起来,完整代码如下:
import time
class BUTTON:
def __init__(self, line, bank, chip=1, mode=2):
from maix import gpio
self.button = gpio.gpio(line, bank, chip, mode)
def is_pressed(self):
if self.button.get_value() != 1:
return True
def __del__(self):
self.button.release()
global key
key = BUTTON(6, "H")
print(key.button.source)
检测按键是否被按下了
while True:
if key.is_pressed():
print("pressed!!")

边栏推荐
- 2022年全球職業教育行業發展報告
- 【AGC】增长服务3-App Linking示例
- Grab efficiency! What has the CTO of this enterprise done right to shorten the cloud planning time by half?
- 图片验证,滑块验证解决
- [HMS core], [FAQ], [Health Kit] encountered some small problems in the process of integrating sports health services. Today, I share with you (Huawei watch, Bracelet + sports health service problems C
- 元宇宙、NFT数字藏品是什么?
- 数据湖(十一):Iceberg表数据组织与查询
- [CVA valuation training camp] how to quickly read the annual reports of listed companies (Lecture 1)
- IPFs record
- C# 程序调试和异常处理(try catch)
猜你喜欢

In the forced update of Huawei applications, occasionally click "exit application" to exit the application

Stc8h Development (XIV): I2C Drive rx8025t high precision Real time clock chip

Idea solves the problem of insufficient memory low memory (user friendly)

thymeleaf介绍与简单应用

初次上路如何提问 - 自学必备技能(附直播回放)

生信周刊第36期

Gerrit基本的权限管理

AB introduction to web performance testing tools

畅游奢侈品元宇宙Louis:The Game,参与NFT系列数字藏品白撸活动| 教程

如何在Kubernetes平台上搭建云IDE Theia
随机推荐
Access authentication of mqtt equipment on jetlinks platform
Competition of "four clouds"
[paid promotion] collection of common problems, basic promotion operation FAQ 2
PCB芯片散热焊盘如何设计?
1.4 process control statement
Implementation of distributed cronab based on cron library extension
污水排放监控,环保数采仪助力城市黑臭水体治理
SouthernBiotech 丨HRP标记Avidin亲和素的应用参数
Using C language to realize the odd number problem of 0-10 -- Original
Sewage discharge monitoring, environmental protection data acquisition instrument to help urban black and odorous water treatment
Grab efficiency! What has the CTO of this enterprise done right to shorten the cloud planning time by half?
一款优秀的信息搜集图形化工具Maltego
元宇宙、NFT数字藏品是什么?
初次上路如何提问 - 自学必备技能(附直播回放)
PostgreSQL source code (5) buffer management
【快应用】快应用用户协议、隐私政策内容中可以多次跳转,点击返回未能返回上一级页面,该如何处理?
An excellent graphical tool for information collection maltego
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
[quick application] PX and VP unit conversion
Error in v-on handler: “ReferenceError: Toast is not defined“