1

私のコードには 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が再度押されるまでその特定のボタンのみが機能します。助けてください!

4

2 に答える 2