7 years, 2 months ago.

calling a function (with some argument) attached with rising edge of interruptIn.

  1. include"mbed.h" PwmOut LED(LED1); InterruptIn button(p5); void on(float& dc); void off(); int main() { float dutycycle=0.05; button.fall(&on(dutycycle));/*<====== this instruction shows and error while program is compiled***/ button.rise(&off); /*error is:-Error: Expression must be an lvalue or a function designator in "assignmentq4_main.cpp", Line: 9, Col: 19 */

while(1) {

} } void on(float& dc) { LED=dc; dc=dc+0.05;

} void off() { LED=0; }

Error: Expression must be an lvalue or a function designator in "assignmentq4_main.cpp", Line: 9, Col: 19 the error message shown above comes referring to instruction shown below: button.fall(&on(dutycycle));

posted by Numair Siddique 23 Oct 2017

1 Answer

7 years, 2 months ago.

Hi Numair,

Unfortunately there is no definition for function callbacks with parameters in InterruptIn rise and fall routines. However you can get your code to work by making duty cycle a global variable.

eg

#include "mbed.h" 
PwmOut LED(LED2); 
InterruptIn button(SW2); 
float dc=0.05; 

void on(); 
void off(); 

int main() { 
    button.fall(on);/*<====== this instruction shows and error while program is compiled***/ 
    button.rise(off); /*error is:-Error: Expression must be an lvalue or a function designator in "assignmentq4_main.cpp", Line: 9, Col: 19 */
    while(1) {

    } 
} 
void on() { 
    LED=dc; dc=dc+0.05;
} 
void off() { LED=0; }

There was a limit not to use dc as global variable. Isn't there any way using class?sir @Michael Bartling

posted by Numair Siddique 23 Oct 2017