Arduino_Automation:
The error says:
"'lastAnalogValue' was not declared in this scope".
So I checked the example sketch in order to find out what I did wrong.
The line missing in my sketch seems to be the following:
int lastButtonState = 0; // previous state of the button
However, as my sensor value is not digital, I am not sure what to replace the 0 with.
You are getting the error because you are trying to use a variable called lastAnalogValue which you have not defined at the top of your program. In C++ all variable must be defined before they can be used.
I can't see the line
int lastButtonState = 0;
anywhere in your program so I don't understand why you are asking about it.
You need to add this line at the top of your program after the line const int threshold1 = 145;
int lastAnalogValue = 0;
You may wish to replace the 0 with one of your threshold values.
...R