Arduino: IO control level variation (2) on ESP32

purpose

Achieve change IO mouth level

Supporting Introduction

In the first document authoring tools have to share how to install tools, new construction and how the programming process, can not understand the point of installation tutorial to see Oh. Hardware is bpibit board. Want to see data points generally open, if there is information on what areas need to add, please leave a comment below.

Authoring Tools: vscode + platformIO installation tutorial

Hardware: bpibit

The main function

  • pinMode( pin, mode) This function is used to configure the corresponding mode pin

  • digitalWrite( pin, val)This function is used to configure the level corresponding pin

Here is the main code. Every line of code has marked its function, the corresponding data pin can see bpibit .

Examples of Use

#include "Arduino.h"
// 设置各引脚别名
const int buttonPin = 35;     // 连接按键的引脚
const int ledPin =  18;      // 连接LED的引脚

// 变量定义
int buttonState = 0;         // 存储按键状态的变量

void setup() {
  // 初始化LED引脚为输出状态、按键引脚为输入状态
  pinMode(ledPin, OUTPUT);      

  pinMode(buttonPin, INPUT);     
}

void loop(){
  // 读取按键状态并存储在变量中
  buttonState = digitalRead(buttonPin);

  // 检查按键是否被按下
  // 如果按键按下,那buttonState应该为高电平
  if (buttonState == HIGH) {     
    // 点亮LED
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // 熄灭LED
    digitalWrite(ledPin, LOW); 
  }
}

to sum up

IO port level change easily done. Changes may be used to determine the high and low of events

Guess you like

Origin blog.csdn.net/weixin_43474408/article/details/90734731