Here's my code:
color_sensor.ino
#include "TCS3200.h"
void setup() {
TCS3200_begin();
Serial.begin(9600);
}
void loop() {
delay(200);
Serial.print(frequencyRead());
Serial.print("kHz");
Serial.println();
}
TCS3200.h
#ifndef _TCS3200
#define _TCS3200
// PINS
uint8_t
OUT = 2,
OE = 3,
S0 = 4,
S1 = 5,
S2 = 6,
S3 = 7;
// PULSE COUNTING
volatile uint16_t
pulse_count;
uint32_t
start_time,
end_time;
void TCS3200_begin() {
pinMode(OE, OUTPUT);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
digitalWrite(OE, LOW);
digitalWrite(S0, HIGH);
digitalWrite(S1, LOW);
digitalWrite(S2, HIGH);
digitalWrite(S3, LOW);
}
void ISR_pulseIncrement() {
pulse_count += 1;
}
attachInterrupt(digitalPinToInterrupt(OUT), ISR_pulseIncrement, RISING);
float frequencyRead() {
// Returns frequency in kHz
end_time = micros();
float frequency = 1000.0 * pulse_count / (end_time - start_time);
start_time = micros();
pulse_count = 0;
return frequency;
}
#endif // _TCS3200
And the error I'm getting is this:
TCS3200.h:39:16: error: expected constructor, destructor, or type conversion before '(' token
attachInterrupt(digitalPinToInterrupt(OUT), ISR_pulseIncrement, RISING);
^
exit status 1
expected constructor, destructor, or type conversion before '(' token
It seems like the IDE wants me to put the attachInterrupt() inside of a function, but when I do that, the ISR is out of scope, so I'm not sure what to do.