Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 3 months ago.
How to pass public class function as an argument to an interrupt function
I am trying to control a DC motor with L293D chip and HCSR-04 sensor as an interrupt for stopping the motors. Pins p8 and p9 are connected to the input of L293D ( on the chip those are pins 2 and 7) But compiler tells me the error when I try to pass class function to an interrupt function. "Error: No instance of overloaded function "mbed::InterruptIn::rise" matches the argument list in "main.cpp", Line: 37, Col: 19"
[code]
- include "mbed.h"
- include "hcsr04.h"
Serial pc(USBTX, USBRX); DigitalOut led1(LED1); HCSR04 usensor(p6,p7); InterruptIn interruptPin(p21); DigitalOut pinToInterrupt(p22);
DigitalOut pin1In(p8); DigitalOut pin2In(p9);
unsigned int dist; void blink();
class Motor{ public: void forwardRear(); void stopRear(); }; void Motor::forwardRear(){ pin1In = 1; pin2In = 0; } void Motor::stopRear(){ pin1In = 0; pin2In = 0; }
int main(){
Motor motor;
pinToInterrupt = 0; interruptPin.rise(&Motor::stopRear);
while(1) { usensor.start(); wait_ms(500); dist = usensor.get_dist_cm(); pc.printf("%d cm\n\r", dist); if( dist < 10){ pinToInterrupt = 1; } else{ pinToInterrupt = 0; } char buttonPressed = pc.getc(); if( buttonPressed == '1') motor.forwardRear(); else motor.stopRear(); } }
void blink(){
for(int i = 0; i < 3; i++){ led1 = 1; wait(0.5); led1 = 0; wait(0.5); } }
[/code]