8 years, 9 months ago.

I m not able to understand the source of error...pls help

<<code>> TextLCD lcd(p19, p20, p21, p22, p23, p24); DigitalOut switchengine(p5); DigitalIn pin_up(p14); DigitalIn pin_down(p15); InterruptIn pin_start(p16); void timeloop(int i); void timeloop(int i){ float T= i; float timeleft = T; lcd.cls(); lcd.locate(1,0); lcd.printf("ENGINE START"); wait(1);

while(timeleft >0){ switchengine=1; if(timeleft<4){ lcd.cls(); lcd.locate(1,0); lcd.printf("Time = %2.2f mn", T*15); wait(0.5); lcd.cls(); } else{ lcd.cls(); lcd.locate(1,0); lcd.printf("Time = %1.2f Hr",(T)*15/60.0); wait(0.5); lcd.cls(); }

lcd.locate(0,1); lcd.printf("Timeleft:%1.2f H",timeleft*15/60.0); wait(900); timeleft; lcd.cls();

} switchengine=0; lcd.cls(); lcd.locate(2,0); lcd.printf("ENGINE OFF");

}

int main() {

int i=0; pin_up.mode(PullDown); pin_down.mode(PullDown); pin_start.mode(PullDown); float time;

lcd.locate(3,0); lcd.printf("SET TIME");

pin_start.rise(&timeloop); Error: No instance of overloaded function "mbed::InterruptIn::rise" matches the argument list in "main.cpp"

}

<</code>>

Question relating to:

1 Answer

8 years, 9 months ago.

Please use the <<code>> and <</code>> tags on separate lines to keep the text readable

TextLCD lcd(p19, p20, p21, p22, p23, p24);
DigitalOut switchengine(p5);
DigitalIn pin_up(p14); 
DigitalIn pin_down(p15);
InterruptIn pin_start(p16);

void timeloop(int i);  // prototype not really needed here if the code follows directly afterwards

void timeloop(int i){
 float T= i;
 float timeleft = T;
 lcd.cls();
 lcd.locate(1,0);
 lcd.printf("ENGINE START");
 wait(1);

 while(timeleft >0){ 
   switchengine=1;
   if(timeleft<4){ 
     lcd.cls();
     lcd.locate(1,0);
     lcd.printf("Time = %2.2f mn", T*15); wait(0.5);
     lcd.cls();
   }
   else{
     lcd.cls();
     lcd.locate(1,0);
     lcd.printf("Time = %1.2f Hr",(T)*15/60.0);
     wait(0.5);
     lcd.cls();
   }

   lcd.locate(0,1);
   lcd.printf("Timeleft:%1.2f H",timeleft*15/60.0);
   wait(900);
   timeleft--;
   lcd.cls();
  }  
  switchengine=0;
  lcd.cls();
  lcd.locate(2,0);
  lcd.printf("ENGINE OFF");
}

int main() {

  int i=0;
  pin_up.mode(PullDown);
  pin_down.mode(PullDown);
  pin_start.mode(PullDown);
  float time;

  lcd.locate(3,0);
  lcd.printf("SET TIME");

  pin_start.rise(&timeloop); // Error: No instance of overloaded function "mbed::InterruptIn::rise" matches the
                                          // argument list in "main.cpp"

}

The problem is caused by the fact that callback functions are not allowed to have parameters.

Remove the ''int i'' parameter in timeloop(int i). Use a global variable if some parameter is needed. Also, the long wait(900) inside a callback function may not be a good idea if you get multiple buttonpresses or add more callbacks from other buttons later on.

Accepted Answer

how can I use global varialble. I dont have any idea about it. Please explain. I want the loop to restart at previous value of 'i', instead of setting its value again when not required.

posted by jayendra mishra 16 Jul 2015

I think you want your engine to run for a set number of 15 minute intervals. This can be done with a Timeout object set to 15 minutes (= 900 s). That object will call a function to decrement the interval counter and update the display.

Something like this:

TextLCD lcd(p19, p20, p21, p22, p23, p24);
DigitalOut switchengine(p5);
DigitalIn pin_up(p14); 
DigitalIn pin_down(p15);
InterruptIn pin_start(p16);

Timeout quarter;      //timeout called every 15min when running
int setNrQuarters;    //selected number of quarters
float runtime;            //currently set runtime interval in quarters
float runtimeleft;       //remaining runtime interval in quarters

void runtimeUpdate();
void displayUpdate();
void startRun() ;

//called when 15min has passed
void runtimeUpdate(){
   runtimeleft--;
   displayUpdate();
}

//update the display and start/stop the engine
void displayUpdate(){

 if (runtimeleft ==0)
   // we are done
   switchengine=0;

   //update display
   lcd.cls();
   lcd.locate(2,0);
   lcd.printf("ENGINE OFF");
 }
 else  {
  //engine should be running
   switchengine=1;

  //update display first line
   lcd.cls();
   lcd.locate(1,0);
   if (runtimeleft < 4){ 
     lcd.printf("Time = %2.2f mn", (runtime*15);
   }
   else{
     lcd.printf("Time = %1.2f Hr", (runtime*15.0)/60.0);
   }
 
  //update display second line
   lcd.locate(0,1);
   lcd.printf("Timeleft:%1.2f H", (runtimeleft*15.0)/60.0);

  // now start timeout to call again in 15min  
  quarter.attach(&runtimeUpdate, 900);
  }  
}


// init and start the run
void startRun() {
 runtime = setNrQuarters;
 runtimeleft = runtime;

 lcd.cls();
 lcd.locate(1,0);
 lcd.printf("ENGINE START");
 wait(1);
 
 displayUpdate();
}

 
int main() {
 
  int i=0;
  pin_up.mode(PullDown);
  pin_down.mode(PullDown);
  pin_start.mode(PullDown);
  float time;
 
  lcd.locate(3,0);
  lcd.printf("SET TIME");
 
  setNrQuarters = 1;    //Initial selected number of quarters

  pin_start.rise(&startRun); // call to (re)start engine run)

  while (1); // just wait for keypress
 
}

posted by Wim Huiskamp 16 Jul 2015

hello mr Huiskamp, could you also please explain me the function of while(1) at the end of the main loop.?

posted by jayendra mishra 21 Jul 2015

Assigned to jayendra mishra 8 years, 2 months ago.

This means that the question has been accepted and is being worked on.