Arduino for BPI:bit 2 : how to control IO ,Running horse lamp experiment

Arduino for BPI:bit 2 : how to control IO ,Running horse lamp experiment,Achieve the change of IO port level

Vscode +platformIO +BPI:bit

main function:

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

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

Here is the main code. Each line of code has the function of marking it, and the corresponding pin data can be seen bpibit

code

#include "Arduino.h"
// Set each pin alias
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); 
  }
}