Good morning, sir,
I'd like you to help me with the code if you can.
I'd like "Program Stat..."
Serial.println("Program start...");
which is displayed once the button is activated or displayed once on the serial monitor but not in a loop.
Thanks
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int doorAPin = 3; // the pin that the pushbutton is attached to
const int doorBPin = 4; //
const int ledPinbutton = 7; // the pin that the LED is attached to
const int ledPindoorA = 8; //
const int ledPindoorB = 9; //
// Variables will change:
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int DeviceState = 0; // current state of DEVICE
int buttonPushCounter = 0; // counter for the number of button presses
int Operation = 0; //
int doorAState = 0; // current state of the Door A
int doorBState = 0; // current state of the Door B
int lastdoorAState = 0; // previous state of the Door A
int lastdoorBState = 0; // previous state of the Door B
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the door pin as a input:
pinMode(doorAPin, INPUT);
// initialize the LED as an output:
pinMode(doorBPin, INPUT);
// initialize the LED as an output:
pinMode(ledPinbutton, OUTPUT);
// initialize the LED as an output:
pinMode(ledPindoorA, OUTPUT);
// initialize the LED as an output:
pinMode(ledPindoorB, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
Serial.println( " Starting the program: Hello ... ");
Serial.println(" ");
} //void setup
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// save the current state as the last state, for next time through the loop
lastButtonState = buttonState;
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button went from off to on:
buttonPushCounter++;
} //if (buttonState == HIGH)
} //if (buttonState != lastButtonState)
// First Press
if (buttonPushCounter % 2 == 1) {
//turn LED BUTTON ON:
digitalWrite(ledPinbutton, HIGH);
//
Serial.println("Program start...");
// DOOR A **************************************
// read the pushbutton input pin:
doorAState = digitalRead(doorAPin);
// compare the DoorState to its previous state
if (doorAState != lastdoorAState) {
if (doorAState == LOW) {// if the door A is Open
// turn LED DOOR A ON:
digitalWrite(ledPindoorA, HIGH);
} //if (doorState == LOW)
else { // door A is closed
// turn LED DOOR A OFF:
digitalWrite(ledPindoorA, LOW);
} //else
}//if (doorAState != lastdoorAState)
// save the current state as the last state, for next time through the loop
lastdoorAState = doorAState;
// *********************************************
// DOOR B **************************************
// read the pushbutton input pin:
doorBState = digitalRead(doorBPin);
// compare the DoorState to its previous state
if (doorBState != lastdoorBState) {
if (doorBState == LOW) {// if the door A is Open
// turn LED DOOR B ON:
digitalWrite(ledPindoorB, HIGH);
} //if (doorState == LOW)
else { // door B is closed
// turn LED DOOR B OFF:
digitalWrite(ledPindoorB, LOW);
} //else
}//if (doorBState != lastdoorBState)
// save the current state as the last state, for next time through the loop
lastdoorBState = doorBState;
// *********************************************
} // if (buttonPushCounter % 2 == 1)
// Second Press
if (buttonPushCounter % 2 == 0) {
// turn LED BUTTON OFF:
digitalWrite(ledPinbutton, LOW);
// turn LED DOOR A OFF:
digitalWrite(ledPindoorA, LOW);
// turn LED DOOR B OFF:
digitalWrite(ledPindoorB, LOW);
//
} //(buttonPushCounter % 2 == 0)
delay(10);
} //void loop
