Hello everybody!I have a problem and i would like your help!I am not very good with codes but i learned some things,as a result i made an app with arduino and bluetooth in order to control 2 devices or lights!Now i want a way to control this devices with both app and wall push buttons!For instance,when i turn on the led2 via app, i want to turn it off via app or wall push button.Also when i turn off the the led2 via app or wall push button i want to turn it on via app or push button!I spent a lot of hours and days but i cannot find the way.Above is the code of arduino.There is also a zip archive!

Hello ieee488, i connected the push button with arduino but i am doing something wrong with the code and it does not work correctly!Arduino drives relay!I want to turn on-off the Led2 for example with one wall push button or appI would like the help of someone who is good with code or did it!above is a photo of connection:

// read the state of the button into a local variable int buttonReading = digitalRead(defButtonpin);

// If the button state has changed, due to noise OR pressing if (buttonReading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); }

// check to see if the current state has been the same for longer than // the debounce delay, if true make, it the current state if ((millis() - lastDebounceTime) > debounceDelay) { // if the "new" button state is different from the current, // take actions for a button press if (buttonReading != buttonState) { buttonState = buttonReading; if (buttonState == HIGH) { if (ledStatus == 10) { ledStatus = 20; digitalWrite(defLEDpin, HIGH); } else { ledStatus = 10; digitalWrite(defLEDpin, LOW); } } } }

// Save the current button state so it is updated for the next loop iteration lastButtonState = buttonReading;

It seems that no one cares! [I do! Please use code tags, the </> button. And delete the extra blank lines. Thanks, Moderator]I added an extra button and led to the previous sketch.I don't know if it is correct but it seems to work well with each push button!The modification that i did to app inventor does not work and the app stucks!i appreciate if someone can help.I include a zip of arduino code and aia app inventor.

// read the state of the button into a local variable int buttonReading = digitalRead(defButtonpin);

// If the button state has changed, due to noise OR pressing if (buttonReading != lastButtonState) { // reset the debouncing timer lastDebounceTime = millis(); }

// check to see if the current state has been the same for longer than // the debounce delay, if true make, it the current state if ((millis() - lastDebounceTime) > debounceDelay) { // if the "new" button state is different from the current, // take actions for a button press if (buttonReading != buttonState) { buttonState = buttonReading; if (buttonState == HIGH) { if (ledStatus == 10) { ledStatus = 20; digitalWrite(defLEDpin, HIGH); } else { ledStatus = 10; digitalWrite(defLEDpin, LOW); } } } }

// LOCAL BUTTON LED CONTROL for the second led and button

// read the state of the button into a local variable int buttonReading2 = digitalRead(defButtonpin2);

// If the button state has changed, due to noise OR pressing if (buttonReading2 != lastButtonState2) { // reset the debouncing timer lastDebounceTime = millis(); }

// check to see if the current state has been the same for longer than // the debounce delay, if true make, it the current state if ((millis() - lastDebounceTime) > debounceDelay) { // if the "new" button state is different from the current, // take actions for a button press if (buttonReading2 != buttonState2) { buttonState2 = buttonReading2; if (buttonState2 == HIGH) { if (ledStatus2 == 30) { ledStatus2 = 35; digitalWrite(defLEDpin2, HIGH); } else { ledStatus2 = 30; digitalWrite(defLEDpin2, LOW); } } } }

// Save the current button state so it is updated for the next loop iteration lastButtonState = buttonReading;

// Save the current button state so it is updated for the next loop iteration lastButtonState2 = buttonReading2;

It's a matter of remembering the state of the light.Then continuously checking for a command from the app or a press of the wall button.If one of them happens, turn off or turn on the light depending on its previous state.Remember the new state.