at20温湿度+bmp280气压+4个AI输入+1个DO+1个DO延时超精简程序-Arduino中文社区 - Powered by Discuz! Archiver

guqiang 发表于 2022-3-28 16:22

at20温湿度+bmp280气压+4个AI输入+1个DO+1个DO延时超精简程序

#define BLINKER_WIFI
#include <Blinker.h>
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#include <SparkFun_Qwiic_Humidity_AHT20.h>
#define BUTTON_1 "btn-abc"
#define BUTTON_2 "btn-123"
#define LED_BUILTIN1       4
#define LED_BUILTIN2       2
BlinkerButton Button1(BUTTON_1);
BlinkerButton Button2(BUTTON_2);
void button1_callback(const String & state)
{
    digitalWrite(LED_BUILTIN1, !digitalRead(LED_BUILTIN1));
    BLINKER_LOG("get button state: ", state);
    if (state == BLINKER_CMD_BUTTON_TAP) {
      BLINKER_LOG("Button tap!");
      Button1.print();
    }

}
void button2_callback(const String & state)
{
    digitalWrite(LED_BUILTIN2, !digitalRead(LED_BUILTIN2));
    digitalWrite(LED_BUILTIN2, HIGH);
    delay(400);
   digitalWrite(LED_BUILTIN2, LOW);
      BLINKER_LOG("Button tap!");
      Button2.print();   
}
void dataRead(const String & data)
{
    BLINKER_LOG("Blinker readString: ", data);
    Blinker.vibrate();
    uint32_t BlinkerTime = millis();   
    Blinker.print("millis", BlinkerTime);
}
AHT20 humiditySensor;
Adafruit_BMP280 bmp;
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
char auth[] = "09a0cd4b4016";
char ssid[] = "Atour";
char pswd[] = "4000606606";
BlinkerNumber Number1("num-abc");
BlinkerNumber Number2("num-abd");
BlinkerNumber Number3("num-abe");
BlinkerNumber Number4("num-abf");
BlinkerNumber Number5("num-abg");
BlinkerNumber Number6("num-abh");
BlinkerNumber Number7("num-abi");
BlinkerNumber Number8("num-abj");
volatile int light5;
volatile int light6;
volatile int light7;
volatile int light8;
void dataStorage(){
         Blinker.dataStorage("num-abg", light5);
         Blinker.dataStorage("num-abh", light6);
         Blinker.dataStorage("num-abi", light7);
         Blinker.dataStorage("num-abj", light8);
         }
         const int potPin5 = 32;
         const int potPin6 = 33;
         const int potPin7 = 34;
         const int potPin8 = 35;
int potValue5 = 0;
int potValue6 = 0;
int potValue7 = 0;
int potValue8 = 0;
void setup() {
Blinker.begin(auth,ssid,pswd);
Serial.begin(115200);
unsigned status;
Wire.begin();
status = bmp.begin();
    BLINKER_DEBUG.stream(Serial);
    pinMode(LED_BUILTIN1, OUTPUT);
    digitalWrite(LED_BUILTIN1, LOW);
    pinMode(LED_BUILTIN2, OUTPUT);
    digitalWrite(LED_BUILTIN2, LOW);
    Blinker.attachData(dataRead);
    Button1.attach(button1_callback);
    Button2.attach(button2_callback);
   if (humiditySensor.begin() == false)
{
    Serial.println("AHT20 not detected. Please check wiring. Freezing.");
    while (1);
}
Serial.println("AHT20 acknowledged.");
}
void loop() {
sensors_event_t temp_event, pressure_event;
bmp_temp->getEvent(&temp_event);
bmp_pressure->getEvent(&pressure_event);
      if (humiditySensor.available() == true)
{
    float temperature = humiditySensor.getTemperature();
    float humidity = humiditySensor.getHumidity();
Serial.print("Temperature: ");
Serial.print(temp_event.temperature);
Serial.println(" C\t");
Serial.print("Pressure:");
Serial.print(pressure_event.pressure);
Serial.println(" hPa");
Serial.print("Temperature: ");
    Serial.print(temperature, 2);
    Serial.print(" C\t");
    Serial.print("Humidity: ");
    Serial.print(humidity, 2);
    Serial.print("% RH");
    Serial.println();
   delay(100);
         potValue5 = analogRead(potPin5);
         potValue6 = analogRead(potPin6);
         potValue7 = analogRead(potPin7);
         potValue8 = analogRead(potPin8);
         light5 = potValue5;
         light6 = potValue6;
         light7 = potValue7;
         light8 = potValue8;
   Number1.print(temp_event.temperature);
   Number2.print(pressure_event.pressure);
   Number3.print(humiditySensor.getTemperature());
   Number4.print(humiditySensor.getHumidity());
   Number5.print(light5);
   Number6.print(light6);
   Number7.print(light7);
   Number8.print(light8);
   Blinker.run();
   }
    delay(500);
}

guqiang 发表于 2022-3-28 16:24

esp32程序arduino程序
页: [1]
查看完整版本: at20温湿度+bmp280气压+4个AI输入+1个DO+1个DO延时超精简程序