数码资讯
1_Arduino-ESP32_外部中断,串口,ADC
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
1_外部中断
#include<Arduino.h>
int pin = 5;
volatile int state = LOW;
void blink()
{
state = !state;
}
void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, FALLING);
}
void loop()
{
digitalWrite(pin, state);
}
2_串口
#include<Arduino.h>
String comchar;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("请输入");
while(Serial.read()>= 0){}//clear serialbuffer
}
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available()>0){
delay(100);
comchar = Serial.readString();
Serial.print("你输入的是");
Serial.println(comchar);
}
}
设置波特率
monitor_speed = 115200
3_ADC
#include<Arduino.h>
// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 34;
// variable for storing the potentiometer value
int potValue = 0;
void setup() {
Serial.begin(115200);
delay(1000);
}
void loop() {
// Reading potentiometer value
potValue = analogRead(potPin);
Serial.println(potValue);
delay(500);
}
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。