FOR Mr.Raping

#include <BluetoothSerial.h>
#include <string.h>
BluetoothSerial BT;

#define MQ7_PIN     39


void setup() {
  Serial.begin(115200);
  BT.begin("ESP32-BT");//請改名
  pinMode(MQ7_PIN, INPUT);
}

int check() {
  int MQ7Val=analogRead(MQ7_PIN), i=0;
  return MQ7Val;
}

void loop() {
  //檢查序列內是否有資料
  while (Serial.available()) {
    //讀取序列資料
    String Sdata = Serial.readString();
    //傳輸給藍芽
    BT.println(Sdata);
  }

  //檢查藍芽內是否有資料
  while (BT.available()) {
    //讀取藍芽資料
    String BTdata = BT.readString();
    //顯示在序列視窗
    if(BTdata == "check"){
      BT.println(check());
    }
    Serial.println(BTdata);
  }
  
  int data = check();
  if(data>300){
    String output = String("danger")+ '\n' + String("Sensor data") + data;
    BT.println(output);
    delay(500);  
  }
  
  delay(1);
}
Made with Slides.com