Hi Arduino Forum,
First time posting. I am getting the following error(s):
Magnets_2.cpp: In function 'void pin3ISR()':
Magnets_2:14: error: expected primary-expression before ']' token
Magnets_2:14: error: expected primary-expression before '{' token
Magnets_2:14: error: expected `;' before '{' token
The program is intended to read two hall sensors to determine linear motion (slide-by) of a weight and fire a piston that will act as a mass arrest system. The program needs to be quick and must be robust enough to function when the beginning position of the weight is between or outside the sensor pair. I've tried a few ways of declaring variables, however I have not found a solution. Maybe a sharp-eyed forum member will see something. Thanks for your help. The code is below:
volatile boolean catchFlag = 1;
volatile boolean switchState[] = {0, 0};
volatile int calls = 0;
const byte magnetPin[] = {2, 3};
const byte ledPin = 13;
const byte numMagnet = 2;
/* START Interrupt Routines */
void pin3ISR() { // Bottom sensor
calls++;
if (calls == 1) { // First instance of call
switchState[] = {1, 0}; // ********* THIS IS LINE 14 ***************
catchFlag = 1;
}
else {
switchState[1] = !switchState[1]; // Not first instance of call
}
if (switchState[0] && !switchState[1] && !catchFlag) { // Indicates second pass of bottom sensor
digitalWrite(ledPin, 1); // Fire piston
catchFlag = 1; // Indicate catch was made in this cycle
for (int i=1; i<100; i++) { // Long delays add up
delayMicroseconds(10000);
}
digitalWrite(ledPin, 0); // Turn off piston
}
}
void pin2ISR() { // Top sensor
calls++;
if (calls==1)
switchState[1] = 0; // First instance of call
else if (calls==2)
switchState[0] = 1; // Second instance of call
else
switchState[0] = !switchState[0];
catchFlag = 0;
}
/* END Interrupt Routines */
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the magnet pins inputs:
for (int i=0; i<=numMagnet-1; i++) {
pinMode(magnetPin[i], INPUT);
}
// make status LEDs output
pinMode(ledPin, OUTPUT);
attachInterrupt(0, pin2ISR, FALLING); // enable interrupt on pin 2 - top sensor
attachInterrupt(1, pin3ISR, FALLING); // enable interrupt on pin 3 - bottom sensor
}
void loop() {
// Do something meaningful
delayMicroseconds(10);
}