Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 打开OLED ESP32的按钮按钮_C++_Button_Arduino_Esp32 - Fatal编程技术网

C++ 打开OLED ESP32的按钮按钮

C++ 打开OLED ESP32的按钮按钮,c++,button,arduino,esp32,C++,Button,Arduino,Esp32,我正在研制一种DHT22传感器,当按下按钮时,它会在OLED上显示读数。我正在使用ArduinoIDE。现在我有传感器工作并在屏幕上显示,但我很难让它只在按下按钮时打开。GPIO 13当前正在接收来自传感器的信号,GPIO 26与电源和接地一起连接到物理按钮。所有带有“//added”的代码都是我为了让按钮工作而添加的新代码。非常感谢您的帮助 在顶部,我补充道: const int ButtonPin = 26; //added const int PushButton; //adde

我正在研制一种DHT22传感器,当按下按钮时,它会在OLED上显示读数。我正在使用ArduinoIDE。现在我有传感器工作并在屏幕上显示,但我很难让它只在按下按钮时打开。GPIO 13当前正在接收来自传感器的信号,GPIO 26与电源和接地一起连接到物理按钮。所有带有“//added”的代码都是我为了让按钮工作而添加的新代码。非常感谢您的帮助

在顶部,我补充道:

const int ButtonPin = 26; //added
const int PushButton;      //added
我得到一个错误:

退出状态1
未初始化常量“按钮”[-fppermissive]

设置
功能中,我添加了:

pinMode(ButtonPin, OUTPUT); //added
pinMode(PushButton, INPUT)://added
    int Push_button_state = digitalRead(PushButton); //added
    if (Push_button_state == HIGH) //added
        float h = dht.readHumidity();
    // Read temperature as Celsius
    float t = dht.readTemperature();

    u8g2.firstPage();
    do {
        draw();
    } while ( u8g2.nextPage() );
    delay(1000);
}
else {  //added
循环
函数中,我添加了:

pinMode(ButtonPin, OUTPUT); //added
pinMode(PushButton, INPUT)://added
    int Push_button_state = digitalRead(PushButton); //added
    if (Push_button_state == HIGH) //added
        float h = dht.readHumidity();
    // Read temperature as Celsius
    float t = dht.readTemperature();

    u8g2.firstPage();
    do {
        draw();
    } while ( u8g2.nextPage() );
    delay(1000);
}
else {  //added

我认为你不清楚你想要实现什么。首先,您只需要ButtonPin变量即可使用按钮。由于您的按钮连接到GPIO 26,您必须将此pin声明为输入。
稍后,您应该使用digitalWrite函数获取pin的状态。根据按钮的连接方式,按下按钮时将收到“0”或“1”。不管怎样,我一直在使用一个非常舒适的库来处理Arduino上的按钮,检查一下。我希望这能有所帮助

错误信息非常清楚。有什么不清楚的?我不确定如何修复您需要初始化的按钮。由于您已将其声明为const,因此必须在创建它时执行此操作。