How to start and stop a function in loop() with Softserial ?

Hi,

I need some help please!

I want to control temperature sensor from bluetooth's phone. SO I want this:

If "1" call " detect_temperature() " , If "0" so "destroy detect_temperature()".

the monitor keep posting temperature and don't response. what is wrong?

void loop(){

if(mySerial.available() > 0){
state = mySerial.read();

  if (state == '1') {
     Serial.println("Smart Vigil enable");
     Vigil = true;  
}
  if (state == '0') {
    Serial.println("Smart Vigil disabled");
     Vigil = false;
   }
}

if (Vigil = true)
{
  detect_temperature();
}else if (Vigil = false)
{ }

void detect_temperature(){
   temp = analogRead(tempPin);
  temp = temp * 0.48828125;
  Serial.print("TEMPRATURE = ");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  delay(100); 
 
}


}

I tried this too

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


  if (state == '1') {
     Serial.println("Smart Vigil enable");
     Vigil = true;  
}
  if (state == '0') {
    Serial.println("Smart Vigil disabled");
     Vigil = false;
   }


if (Vigil = true)
{
  detect_temperature();
}else if (Vigil = false)
{ }

void detect_temperature(){
   temp = analogRead(tempPin);
  temp = temp * 0.48828125;
  Serial.print("TEMPRATURE = ");
  Serial.print(temp);
  Serial.print("*C");
  Serial.println();
  delay(100); 
 
}

thanks

Try always putting a double equals == in all if statements.

if (Vigil = true)

BZZZZT!

Ooop thanks but I found it

I just have to chage

if (Vigil= true ) .... if (Vigil= false)

to

if (Vigil) ....if (!Vigil)

That is an alternitave but our suggestions are valid.

There is no need to test for not true, first because if it is true the else condition will automatically only get done on not true, and second if you do not want to do anything then don't have the else at all.