error: "Invalid use of void expression" when using attachInterrupt

Hi everyone,

I’m quite new with Arduino (writing simple programs for a month now) and for a small project I need to write one (big) sketch including several smaller sketches (e.g. a color sensor and a NFC reader).
Individual, the sketches will compile and run correctly, but when I want to put them together I get an error using attachInterrupt, namely: Invalid use of void expression.
Does anyone know how to fix this error and perhaps the background information so I can avoid this error in the future?
Thanks in advance!

P.S. I put a part my code down below and the individual sketches as a attachment.

// Include Colorsensor Libraries
  #include <TimerOne.h>

// Colorsensor Values
  #define S0     6   // Please notice the Pin's define
  #define S1     5
  #define S2     4
  #define S3     3
  #define OUT    2
  
  int   g_count = 0;    // count the frequecy
  int   g_array[3];     // store the RGB value
  int   g_flag = 0;     // filter of RGB queue
  float g_SF[3];        // save the RGB Scale factor
  int value[3];         // used to determine definite color
  char color;

void setup() {      
  Serial.begin(9600);
  Colorsensor_setup();
}

void loop() {// This will be filled in later, I'm still assemblying the code
}


//Tab 2, Colorsensor functions
int Colorsensor_setup()
{
  // Values and pins used by Colorsensor
  #define S0     6  
  #define S1     5
  #define S2     4
  #define S3     3
  #define OUT    2
  
  int   g_count = 0;    // count the frequecy
  int   g_array[3];     // store the RGB value
  int   g_flag = 0;     // filter of RGB queue
  float g_SF[3];        // save the RGB Scale factor
  int value[3];         // used to determine definite color
  char color;           // char including the definite color

  // PIECE THAT INCLUDES THE ERROR WHEN UNCOMMENTED
  /*  
  TSC_Init();
  Serial.begin(9600);
  Timer1.initialize();             // default is 1s
  Timer1.attachInterrupt(TSC_Callback(g_count, g_flag, g_array));  
  attachInterrupt(0, TSC_Count(g_count), RISING);  
  
  delay(4000);
  */
  
  for (int i=0; i<3; i++){
    Serial.println(g_array[i]);
  }
  
  g_SF[0] = 255.0/ g_array[0];     //R Scale factor
  g_SF[1] = 255.0/ g_array[1];     //G Scale factor
  g_SF[2] = 255.0/ g_array[2];     //B Scale factor

  Serial.print("R Scale Factor:");
  Serial.println(g_SF[0]);
  Serial.print("G Scale Factor:");
  Serial.println(g_SF[1]);
  Serial.print("B Scale Factor:");
  Serial.println(g_SF[2]);
}

// Init TSC230 and setting Frequency.
void TSC_Init()
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);
  
  digitalWrite(S0, LOW);  // OUTPUT FREQUENCY SCALING 2%
  digitalWrite(S1, HIGH); 
}
  
// Select the filter color 
void TSC_FilterColor(int Level01, int Level02)
{
  if(Level01 != 0){
    Level01 = HIGH;
  }
  if(Level02 != 0){
    Level02 = HIGH;
  }
  digitalWrite(S2, Level01); 
  digitalWrite(S3, Level02); 
}
  
void TSC_Count(int g_count)
{
  g_count ++ ;
}
  
void TSC_Callback(int g_count, int g_flag, int *g_array)
{
  switch(g_flag)
  {
    case 0: 
         Serial.println("->WB Start");
         TSC_WB(LOW, LOW, g_count, g_flag);                   //Filter without Red
         break;
    case 1:
         Serial.print("->Frequency R=");
         Serial.println(g_count);
         g_array[0] = g_count;
         TSC_WB(HIGH, HIGH, g_count, g_flag);                 //Filter without Green
         break;
    case 2:
         Serial.print("->Frequency G=");
         Serial.println(g_count);
         g_array[1] = g_count;
         TSC_WB(LOW, HIGH, g_count, g_flag);                  //Filter without Blue
         break;
  
    case 3:
         Serial.print("->Frequency B=");
         Serial.println(g_count);
         Serial.println("->WB End");
         g_array[2] = g_count;
         TSC_WB(HIGH, LOW, g_count, g_flag);                  //Clear(no filter)   
         break;
   default:
         g_count = 0;
         break;
  }
}
  
int TSC_WB(int Level0, int Level1, int g_count, int g_flag)   //White Balance
{
  g_count = 0;
  g_flag ++;
  TSC_FilterColor(Level0, Level1);
  Timer1.setPeriod(1000000);              // set 1s period
}

Colorsensor.ino (2.85 KB)

NFC.ino (1.43 KB)

Testcode.ino (1.08 KB)

  attachInterrupt(0, TSC_Count(g_count), RISING);

attachInterrupt must take a function taking no arguments as its second parameter. You are not supplying that. Also, by supplying an argument (g_count) you are calling the function, not supplying its address.

See: Gammon Forum : Electronics : Microprocessors : Function pointers / function callbacks / function variables.

Dear Nick,

Thanks for answering so quick. I think I understand and indeed my sketch don't give compile errors anymore. Btw, you're site helped a lot.
Thanks again!