2 inputs to control 1 output.

So I have a bluetooth module and I need to be able to turn an the same led on and off with my phone and a button. Ex. If I were to send "On" to my arduino from my phone it would turn the led on then I would be able to hit the button and the led would turn off and vise versa. I have the code for each input working correctly separatley but I need to combine them I have tried but it doesnt seem to work. Also I am kinda new to this so I may have tried it completely wrong. Thanks for any help in advance here is my code:

Here is the standalone bluetooth code without button:

int ledPin = 3; 
int state = 0;
int flag = 0; 

void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);

 Serial.begin(9600); // Default connection rate for my BT module
}

void loop() {

 if(Serial.available() > 0){
 state = Serial.read();
 flag=0;
 }

 if (state == '0') {
 digitalWrite(ledPin, LOW);
 if(flag == 0){
 Serial.println("LED: off");
 flag = 1;
 }
 }

 else if (state == '1') {
 digitalWrite(ledPin, HIGH);
 if(flag == 0){
 Serial.println("LED: on");
 flag = 1;
 }
 }
}

Here is my standalone code for the button(I used the example Debounce)

const int buttonPin = 2;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin

// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // set initial LED state
  digitalWrite(ledPin, ledState);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button 
  // (i.e. the input went from LOW to HIGH),  and you've waited 
  // long enough since the last press to ignore any noise:  

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  } 
  
  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        ledState = !ledState;
      }
    }
  }
  
  // set the LED:
  digitalWrite(ledPin, ledState);

  // save the reading.  Next time through the loop,
  // it'll be the lastButtonState:
  lastButtonState = reading;
}

And Here is how I tried to mash them together:

int ledPin = 3; 
int state = 0;
int flag = 0; 
int buttonPin = 2;

int ledState = HIGH;         
int buttonState;             
int lastButtonState = LOW;  

long lastDebounceTime = 0;  
long debounceDelay = 50; 

void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, ledState);
 pinMode(buttonPin, INPUT);

 Serial.begin(9600); // Default connection rate for my BT module
}

void loop() {
 int reading = digitalRead(buttonPin);

  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
  
    
  if ((millis() - lastDebounceTime) > debounceDelay) {
  if (reading != buttonState) {
      buttonState = reading;

 if(Serial.available() > 0){
 state = Serial.read();
 flag=0;
  }

 if (state == 'On' || buttonState == HIGH){
 digitalWrite(ledPin, LOW);
 if(flag == 0){
 Serial.println("LED: off");
 flag = 1;
  }
  }

 else if (state == 'Off' || reading != buttonState){
 digitalWrite(ledPin, HIGH);
 if(flag == 0){
 Serial.println("LED: on");
 flag = 1;
  }
  }
 }
 }


 digitalWrite(ledPin, ledState);
 lastButtonState = reading;
}
 if (state == 'On' || buttonState == HIGH){

Single quotes are for single characters. Please post a picture of your keyboard with the 'On' key circled.

You read ONE character from the serial port. That ONE character will NEVER be 'On'.

Thanks for the help I changed them to 0 and 1 but it still doesnt work do you know a better way about doing this

Thanks for the help I changed them to 0 and 1

Perhaps you should try '0' and '1'.

In one program you seem to invert the LED if state is ‘0’. In the other program it depends on buttonState being HIGH.

When you combine them your probably need something like

if (state == '0' || buttonState == HIGH) {

…R