Hi all! I am new returning to coding after ~20 years and I find myself stuck on likely a very basic issue...
I am trying to use 2 push buttons to control in and out on an actuator and do not undestand why i am getting error "expected ')' before numeric constant" on my 4th line of code as seen below:
#define BUTTON_PIN 2
#define BUTTON_PIN 3
int outButtonState = digitalRead(BUTTON_PIN 3);
int inButtonState = digitalRead(BUTTON_PIN 2); // ERROR IS WITH THIS LINE
Please advise with out beating me up too much... lol
The syntax of define means - "define a macros BUTTON_PIN and set its value to 2"
So the two lines at beginning of your code defines the same macros BUTTON_PIN twice. If you need to define a two pins, the names must not be the same.
For example:
#define BUTTON_PIN1 2
#define BUTTON_PIN2 3
Than, when you use the macro in the code, you must place only the name rather than "name value" pair. So the correct variant of your 4th line will be:
Part of using # define or other ways to give names to numbers is to... leave the numbers behind, and to make one place where the identifier <-> number translation is done, in the case you want to change your wiring, or TBH to fix mistakes in software instead of hardware, like:
#define BUTTON_A 2
#define BUTTON_B 3
int outButtonState = digitalRead(BUTTON_B);
int inButtonState = digitalRead(BUTTON_A);