Invalid use of void expression

Hello, I keep getting this void expression error and have no idea how to fix it. I've been playing around with interrupts and it was working fine, when the interrupt functions did not have parameters, but with parameters it doesn't compile.
The code was mostly taken from here and then adjusted: http://kunoichi.be/projects/arduino-and-detecting-objects-with-multiple-hc-sr04-sensor/

Hardware:
NodeMCU 1.0 (ESP12-e)
4x HC-SR04 Ultrasoundsensors

Code:

#define tINT 4 // Total number of interrupts
#define triggerPin 0 // Pin number for the common trigger
#define pingDelay 50 // How many milliseconds between each measurement ; keep > 5ms
#define debugDelay 200 // How many milliseconds between each Serial.print ; keep > 200ms
#define soundSpeed 343.0 // Speed of sound in m/s
volatile unsigned long travelTime[tINT]; // Place to store traveltime of the pusle
volatile unsigned long startTime[tINT]; // Place to store ping times (interrupt)
float distance[tINT]; // Calculated distances in cm
unsigned long lastPollMillis;
unsigned long lastDebugMillis;
// Sensoren. Interrupt Pins on: D0-D8.
// Pinout: https://www.teachmemicro.com/nodemcu-pinout/
// Interrupt Pins: NodeMCU GPIO Interrupts with Arduino IDE | NodeMCU
const int sensor_vl = 4;
const int sensor_hl = 2;
const int sensor_vr = 14;
const int sensor_hr = 12;

void ICACHE_RAM_ATTR call_INT(int cur_sensor, int index_no);
void ICACHE_RAM_ATTR interruptHandler(bool pinState, int nIRQ);
/****************************************************************
SETUP
****************************************************************/
void setup()
{
Serial.begin(115200);
while (!Serial) {
; // Wait for Serial
}
Serial.println("--- Serial monitor started ---");
pinMode(triggerPin, OUTPUT); // Set common triggerpin as output
// Manage interrupt pins here
pinMode(sensor_vl, INPUT);
pinMode(sensor_hl, INPUT);
pinMode(sensor_vr, INPUT);
pinMode(sensor_hr, INPUT);

attachInterrupt(sensor_vl, call_INT(sensor_vl, 0), CHANGE );
attachInterrupt(sensor_hl, call_INT(sensor_hl, 1), CHANGE );
attachInterrupt(sensor_vr, call_INT(sensor_vr, 2), CHANGE );
attachInterrupt(sensor_hr, call_INT(sensor_hr, 3), CHANGE );
// END
lastPollMillis = millis();
lastDebugMillis = millis();
}
/****************************************************************
LOOP
**************************************************************/
void loop()
{
// Poll every x ms
if (millis() - lastPollMillis >= pingDelay)
{
doMeasurement();
lastPollMillis = millis();
}
// Print every y ms (comment out in production)
if (millis() - lastDebugMillis >= debugDelay)
{
for (int i = 0; i < tINT; i++) {
Serial.print(distance
);

  • Serial.print(" - ");*
  • }*
  • Serial.println();*
  • lastDebugMillis = millis();*
  • }*
    }
    /****************************************************************
  • Retrieve measurement and set next trigger*
    ****************************************************************/
    void doMeasurement()
    {
  • // First read will be 0 (no distance calculated yet)*
  • // Read the previous result (pause interrupts while doing so)*
  • noInterrupts(); // cli()*
  • for (int i = 0; i < tINT; i++)*
  • {*
    distance = travelTime / 2.0 * (float)soundSpeed / 10000.0; // in cm
    * }*
    * interrupts(); // sei();*
    * // Initiate next trigger*
    * digitalWrite(triggerPin, HIGH); // HIGH pulse for at least 10µs*
    * delayMicroseconds(10);*
    * digitalWrite(triggerPin, LOW); // Set LOW again*
    }
    /****************************************************************
    * INTERRUPT handling*
    ****************************************************************/
    void call_INT(int cur_sensor, int index_no)
    {
    * byte pinRead = digitalRead(cur_sensor);
    interruptHandler(pinRead, index_no);
    _}
    // Common function for interrupts*
    void interruptHandler(bool pinState, int nIRQ)
    {
    * unsigned long currentTime = micros(); // Get current time (in µs)
    if (pinState)
    {
    // If pin state has changed to HIGH -> remember start time (in µs)
    startTime[nIRQ] = currentTime;
    }
    else*
    * {
    // If pin state has changed to LOW -> calculate time passed (in µs)
    travelTime[nIRQ] = currentTime - startTime[nIRQ];
    }
    }
    Error:
    In function 'void setup()':_

    hc-sr04_ultraschallsensor_multiple_test:38:61: error: invalid use of void expression
    attachInterrupt(sensor_vl, call_INT(sensor_vl, 0), CHANGE );
    _ ^_
    hc-sr04_ultraschallsensor_multiple_test:39:61: error: invalid use of void expression
    attachInterrupt(sensor_hl, call_INT(sensor_hl, 1), CHANGE );
    _ ^_
    hc-sr04_ultraschallsensor_multiple_test:40:61: error: invalid use of void expression
    attachInterrupt(sensor_vr, call_INT(sensor_vr, 2), CHANGE ); *

How can an interrupt handler have arguments?

Please remember to use code tags when posting code

with parameters it doesn't compile.

A strong suggestion that you can't have parameters.

Please edit your post to change quote tags to code tags.

Oh well, that's a bummer. So every single pin with an interrupt requires it's own interrupt function?

Yes, but each could be a stub, that provides arguments to a common routine.

The pin change interrupts share one interrupt per 8 bit port. The ISR has to determine which pin in the port triggered the interrupt.

Wrap them in a lambda function:

  attachInterrupt(sensor_vl, []{ call_INT(sensor_vl, 0); }, CHANGE );
  attachInterrupt(sensor_hl, []{ call_INT(sensor_hl, 1); }, CHANGE );
  attachInterrupt(sensor_vr, []{ call_INT(sensor_vr, 2); }, CHANGE );
  attachInterrupt(sensor_hr, []{ call_INT(sensor_hr, 3); }, CHANGE );

Pieter

ESP8266 and ESP32 cores have an overload of attachInterrupt() that accepts a void * argument. That value is passed back to the user's ISR when invoked (again as a void *). Very convenient for certain applications. Of course, it's a little bit of smoke and mirrors as the REAL ISR vector implemented in the core still doesn't take any arguments.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.