Noob-Help With Firefighter Code

Im working on my first firefighter using an arduino mini, 3 ir sensors, and two photoresistors, and a fan. ive got the navigation code written, but im unsure how to use the photoresistors, ive tested them on the board and theyre reading properly, when the sensors see flame i need to interrupt the current loop and then navigate towards the flame...any suggestions/help, im completely lost

Thanks!

The much i was able to get what you are saying is that The void loop() will be running the code that iterates and checks for the Fire again and again and as soon it senses one such situation it call another block of code in which further instruction's would be laid?, If this is the case just use Another Function like void furtherinst() and call it from the place you want the code to execute or based on some Condition like if (Condition) { furtherinst(); }

I'm sorry i wasnt more descriptive earlier..

My robot can navigate the maze, I am trying to use the attachInterrupt(); command using my photosensors, this is what i have right now, and i cannot get the interrupt to work, can you use the attachInterrupt(); command with an analog sensor? this is what my code looks like, at least the part thats giving me trouble anyway

#include <EncodersAB.h>
#include <Motors.h>
#include <SharpIR.h>

Motors drive = Motors(); //drive motors
SharpIR rightir = SharpIR(GP2D12,3);
SharpIR leftir = SharpIR(GP2D12,1);
SharpIR centerir = SharpIR(GP2D12,2);
volatile int flame=0;
int r=analogRead(5);
int l=analogRead(4);

void setup()
{
// This version separates the initial turn and then allows the bot to detect a room from the forward function
Serial.begin(38400);
int r=analogRead(5);
int l=analogRead(4);
interrupts();
attachInterrupt(5,flame_found,FALLING); //There are two different photoresistors
attachInterrupt(4,flame_found,FALLING);

delay(500);

}

void loop()
{
int r=analogRead(5);
int l=analogRead(4);

if(int flame = 1) //this should happen after the flame_found function
{
drive.set(100,100);
delay(1000);

}

}

void flame_found()
{

int flame=1;
}

First of all change if(variable = something) to if(variable == something).

"=" is an Assignment Operator in C/C++ so it assigns values to the left side variable with the right side value of the "=" operator.

"==" is an comparison operator used to compare one variable with another or one value with another.

Also, Declare int flame somewhere above and then use it with just it's name and not the variable prefix (i.e. the int or char whatsoever).

Ok, I changed that, but i dont think its calling the function,

here is my code that im trying to make work

#include <EncodersAB.h>
#include <Motors.h>
#include <SharpIR.h>

Motors drive = Motors(); //drive motors
SharpIR rightir = SharpIR(GP2D12,3);
SharpIR leftir = SharpIR(GP2D12,1);
SharpIR centerir = SharpIR(GP2D12,2);
volatile int flame=0;
int r=analogRead(5);
int l=analogRead(4);

void setup()
{
// This version separates the initial turn and then allows the bot to detect a room from the forward function
Serial.begin(38400);
int r=analogRead(5);
int l=analogRead(4);
interrupts();
attachInterrupt(5,flame_found,FALLING);
//attachInterrupt(4,flame_found,LOW);

delay(500);

}

void loop()
{
int r=analogRead(5);
int l=analogRead(4);

if(flame==1) //After the flame_found fucntion is called these commands should run right?
{
drive.set(100,100);
delay(1000);

}
Serial.println(r);
delay(1000);

}
void flame_found()
{

int flame=1; //So when this is equal to 1 the bot should move forward, or at least i think that's how it should work, Ive tested the sensors and they are working
}

This:

void flame_found()
{
  
      int flame=1; //So when this is equal to 1 the bot should move forward, or at least i think that's how it should work, Ive tested the sensors and they are working 
}

Should be

void flame_found()
{
  
      flame=1; //So when this is equal to 1 the bot should move forward, or at least i think that's how it should work, Ive tested the sensors and they are working 
}

Your version is declaring another local int in flame found. Your global flame variable will never get touched.

#include <EncodersAB.h>
#include <Motors.h>
#include <SharpIR.h>


Motors drive = Motors(); //drive motors
SharpIR rightir = SharpIR(GP2D12,3);
SharpIR leftir = SharpIR(GP2D12,1);
SharpIR centerir = SharpIR(GP2D12,2);
volatile int flame=0;
int r=analogRead(5);
int l=analogRead(4);


void setup()
{   
  // This version separates the initial turn and then allows the bot to detect a room from the forward function
  Serial.begin(38400);
  int r=analogRead(5);
  int l=analogRead(4);
  interrupts(); 
  attachInterrupt(5,flame_found,FALLING); //My photosensors are attatched to analog ports four and five, can they still trigger an  intterupt?
  //attachInterrupt(4,flame_found,FALLING); 
 
  delay(500);
 

}

void loop()
{
  int r=analogRead(5);
  int l=analogRead(4);

    if(flame==1) //After the flame_found fucntion is called these commands should run right?
  {
    drive.set(100,100);
    delay(1000);
   
  }
  Serial.println(r);
delay(1000);
 
}
 void flame_found()
{
 
      flame=1; //So when this is equal to 1 the bot should move forward, or at least i think that's how it should work, Ive tested the sensors and they are working
}

Can i use the attachInterrupt command with the analog ports? I cant seem to get it to work

thanks to everyone for your input so far btw, i really appreciate it