我的代码有 5 个按钮。我希望如果按下按钮 2,则按钮 3、4 和 5 被禁用,因此即使按下它们也不起作用。我想将按钮 1 用作重置按钮。我的代码是
#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>
const int BUTTON1_PIN = 22;
const int BUTTON2_PIN = 24;
const int BUTTON3_PIN = 26;
const int BUTTON4_PIN = 28;
const int BUTTON5_PIN = 30;
int lbtn1S = HIGH;
int lbtn2S = HIGH;
int lbtn3S = HIGH;
int lbtn4S = HIGH;
int lbtn5S = HIGH;
int btn1S;
int btn2S;
int btn3S;
int btn4S;
int btn5S;
int buttonDown = 0;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
delay(1000);
pinMode(BUTTON1_PIN, INPUT_PULLUP);
pinMode(BUTTON2_PIN, INPUT_PULLUP);
pinMode(BUTTON3_PIN, INPUT_PULLUP);
pinMode(BUTTON4_PIN, INPUT_PULLUP);
pinMode(BUTTON5_PIN, INPUT_PULLUP);
}
void loop() {
int btn1S = digitalRead(BUTTON1_PIN);
int btn2S = digitalRead(BUTTON2_PIN);
int btn3S = digitalRead(BUTTON3_PIN);
int btn4S = digitalRead(BUTTON4_PIN);
int btn5S = digitalRead(BUTTON5_PIN);
// --------- For Button 1 -------------------
if (lbtn1S == LOW && btn1S == HIGH){
Serial.print("button 1 state: ");
Serial.println(btn1S);
//Serial1.print("\xFF\xFF\xFF");
Serial1.print("page 0");
Serial1.print("\xFF\xFF\xFF");
Serial.println ("Hello World 1");
}
// --------- For Button 2 -------------------
if (lbtn2S == LOW && btn2S == HIGH){
Serial.print("button 2 state: ");
Serial.println(btn2S);
//Serial1.print("\xFF\xFF\xFF");
Serial1.print("page 1");
Serial1.print("\xFF\xFF\xFF");
Serial.println ("Hello World 2");
}
// --------- For Button 3 -------------------
if (lbtn3S == LOW && btn3S == HIGH){
Serial.print("button 3 state: ");
Serial.println(btn3S);
//Serial1.print("\xFF\xFF\xFF");
Serial1.print("page 2");
Serial1.print("\xFF\xFF\xFF");
Serial.println ("Hello World 3");
}
// --------- For Button 4 -------------------
if (lbtn4S == LOW && btn4S == HIGH){
Serial.print("button 4 state: ");
Serial.println(btn4S);
//Serial1.print("\xFF\xFF\xFF");
Serial1.print("page 3");
Serial1.print("\xFF\xFF\xFF");
Serial.println ("Hello World 1");
}
// --------- For Button 5 -------------------
if (lbtn5S == LOW && btn5S == HIGH){
Serial.print("button 5 state: ");
Serial.println(btn5S);
//Serial1.print("\xFF\xFF\xFF");
Serial1.print("page 4");
Serial1.print("\xFF\xFF\xFF");
Serial.println ("Hello World 1");
}
lbtn1S = btn1S;
lbtn2S = btn2S;
lbtn3S = btn3S;
lbtn4S = btn4S;
lbtn5S = btn5S;
}
谁能帮我解决这个问题!我需要这样做,以便如果我按下按钮 1,所有其他按钮也可以正常工作,但如果我按下按钮 2、4、3 或 5,则只有该特定按钮才能工作,直到再次按下按钮 1。请帮忙!