1_Arduino-ESP32_外部中斷,串口,ADC

1_外部中斷


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_串口


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);
     
    }
 
}
複製代碼

3_ADC


// 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);
}
複製代碼

相關文章
相關標籤/搜索