Help Needed. Bluetooth with while loop.

Hi guys, anyone knows how to code for the following requirement?

My code below only able to on and off. Always waiting for new input from Bluetooth. Anyway to continue the loop if there is no input as the value remains as 1?

  1. If there is no input from Bluetooth, continue the while loop
  2. If there is input from Bluetooth, grab the value and check for condition
#include <SoftwareSerial.h>

SoftwareSerial Bluetooth (3, 4); //Setting 3 and 4 as TX & RX
char Incoming_value;
char New_Incoming_value;

void setup()
{
  Serial.begin(9600);
  Bluetooth.begin(9600);

  if (Bluetooth.available() > 0) {
    Incoming_value = Bluetooth.read();
  }
}

void loop() {

  readBluetooth();

  if (Incoming_value == '1') {
    onMode();
  }
  if (Incoming_value == '0') {
    offMode();
  }
}

void readBluetooth() {
  while (Bluetooth.available() > 0) {
    New_Incoming_value = Bluetooth.read();
    if (New_Incoming_value != Incoming_value) {
      if (Incoming_value == '1') {
        Incoming_value = 0;
      }
      else {
        Incoming_value = 1;
      }
    }
  }
  Incoming_value = New_Incoming_value;
}

void onMode() {
  while (Incoming_value == '1') {
    Serial.print("ON")
    readBluetooth();
  }
}

void offMode() {
  Serial.println("OFF");
}
  1. If there is no input from Bluetooth, continue the while loop
  2. If there is input from Bluetooth, grab the value and check for condition

It looks to me as though a while loop is the wrong tool for the job. Your requirements specifically use if to explain what you want so why not use if in the program instead of while and let the loop() function do what it is best at ?

I have tried earlier but no luck. Perhaps you could enlighten with the idea?

It was the while loop in readBluetooth() that I was suggesting be replaced by if. This would keep loop() repeating which is what you say you want. The while in onMode() could also be an if for the same reason.