当前位置:网站首页>V831 - use of IO port
V831 - use of IO port
2022-07-18 17:34:00 【Me and nano】
V831
List of articles
Preface
Learn before 831 When ,io There is always something wrong with your mouth , Later, a new image was updated , It should be the official bug Repair the
One 、GPIO
GPIO, Full name General-Purpose Input/Output( General input output ), It is a general pin that can be configured and controlled dynamically during software running . be-all GPIO The initial state after power on is input mode , It can control the output of the level and obtain the level change of the peripheral .
Two 、 Buzzer

Over control GPIO Output high and low levels , Before using, you need to load the corresponding board GPIO To configure . By viewing the pin definition diagram of the development board , Determine what you are using IO Pin number , For example, the following is MaixII-Dock Of GPIO PH6 Pin , You need to use gpio.gpio(6, “H”, 1), Define , The complete code is as follows :
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()
Then you can hear the buzzer ring , The same code as before , But it just doesn't ring .
3、 ... and 、 Key
take GPIO Set to input mode , To get the level change of the board . Need to be in GPIO Add one more parameter when instantiating , To set up GPIO The pattern of .
key = gpio.gpio(6, "H", 1, line_mode = 2)#2 Set to input mode , This parameter defaults to 1, Output mode
GPIO It needs to be released after use , Otherwise, it will be occupied , adopt gpio.release() Release GPIO Or use a class to encapsulate , The complete code is as follows :
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)
Check whether the key is pressed
while True:
if key.is_pressed():
print("pressed!!")

边栏推荐
猜你喜欢

Alipay sandbox tests mobile website payment, prompting that the merchant's cooperation agreement has expired and cannot continue to be used

浅析websocket劫持

HCIA-R&S自用笔记(9)数据转发过程、单播/多播/组播

An excellent graphical tool for information collection maltego

五 其它目标和通用选项的介绍

一 kernel编译系统概述

Vim使用学习以及ideaVim(持续补充)

“四朵云”的较量

How to multiply bank revenue through customer value analysis

我回来了
随机推荐
多米诺骨牌上演:三箭资本崩盘始末
One week's wonderful content sharing (issue 12) repetition
Sewage discharge monitoring, environmental protection data acquisition instrument to help urban black and odorous water treatment
Postgresql源码(7)Xlog格式
Postgresql源码(10)Xlog组装
[CVA valuation training camp] how to quickly read the annual reports of listed companies (Lecture 1)
给定一个整数数组nums和一个目标值target,在该数组中找出 和为 目标值的那两个整数,并返回他们的数组下标。
面试官:Redis主从集群切换数据丢失问题如何应对?
How to design PCB chip heat dissipation pad?
How should both parties bear the large amount of child support after divorce
thymeleaf介绍与简单应用
如何在Kubernetes上搭建code-server 云IDE平台
自建个性化自动报价系统,应对多变报价模式
离婚后,子女大额抚养费双方如何负担
如何在Kubernetes平台上搭建云IDE Theia
PostgreSQL source code (7) xlog format
How to build a code server cloud ide platform on kubernetes
Vim使用学习以及ideaVim(持续补充)
leetcode专项 动态规划入门
Keil MDK5.37以上版本自行添加AC5(ARMCC)编译器的方法