Hello, all! I am working on a Christmas gift for my mother (procrastination, I know. School has been tough, though!), and I recently ran into this issue. I have a working knowledge of Wiring language, but I don’t have a strong understanding of C++, so I hope I may be doing something that is so obvious to the particle community that it’ll be easily fixed.
So, the problem: I’m using a rotary encoder to scroll some junk on an LCD which I’m operating over I2C. I’ve set up an interrupt on one of the encoder pins to catch the rising edge of the encoder signal, and this seems to be where the issue is arising. When compiling, I get an error code which says, “Error: invalid use of void expression.” The program worked successfully for a long while using the interrupt, but I must have changed something in the code recently, causing it to break. I have added use of the HTU21D library today, but after commenting all HTU-related lines out and compiling again, I have determined that that is most likely not the issue. The code is as follows:
#include "HTU21D/HTU21D.h"
#include "LiquidCrystal_I2C_Spark/LiquidCrystal_I2C_Spark.h"
LiquidCrystal_I2C *lcd;
//HTU21D htu = HTU21D();
int encoderA=3;
int encoderB=4;
int encoderButton=5;
int floatSwitch=7;
int moistureL=A1;
int moistureR=A2;
int pumpL=A3;
int pumpR=A4;
int volatile pos=0;
void setup(void)
{
Serial.begin(9600);
//htu.begin();
lcd = new LiquidCrystal_I2C(0x27, 20, 4);
lcd->init();
lcd->backlight();
lcd->clear();
lcd->setCursor(2,1);
lcd->print("Initializing");
pinMode(encoderA, INPUT);
attachInterrupt(encoderA, encoder(), RISING);
pinMode(encoderB, INPUT);
pinMode(encoderButton, INPUT);
pinMode(floatSwitch, INPUT);
pinMode(moistureL, INPUT);
pinMode(moistureR, INPUT);
pinMode(pumpL, OUTPUT);
pinMode(pumpR, OUTPUT);
}
void loop(void){
//Serial.println("======================");
//Serial.print("Temp: "); Serial.println(htu.readTemperature());
//Serial.print("Hum: "); Serial.println(htu.readHumidity());
//delay(1000);
}
void encoder(void){
if (digitalRead(D3) == digitalRead(D4)){
pos--;
Serial.println("E");
}
else if(digitalRead(D3) != digitalRead(D4)){
pos++;
Serial.println("N-E.");
}
}
Also peculiar, the error reports that the issue is occurring multiple lines above where the actual problematic code. This is confirmed by commenting out the attachInterrupt statement and re-compiling (or attempting to, anyway). Any ideas on this? I’ll appreciate any help I can get.