STATE MACHINE

Hy everybody,
many thanks in advance at who will tell me where i'm wrong.
I want just control an led, with BUTTON to switch it on and with BUTTON1 to switch it off. If now i run the code the led is still on and no control with buttons.
Thanks again.
Andy.

PIN definitions
#define RELAY_PIN 42
#define BUTTON 22
#define BUTTON1 24
// FSM states
#define PINZA_CHIUSA  0
#define PINZA_APERTA   1

int statopinza;

void setup() {
pinMode(BUTTON, INPUT);
pinMode(BUTTON1, INPUT);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
statopinza = PINZA_CHIUSA;
}

void loop() {
int apri;
int chiudi;  
apri=digitalRead(BUTTON); 
chiudi=digitalRead(BUTTON1);
switch(statopinza) 
{
case PINZA_CHIUSA:
 
if(apri=HIGH) 
{
digitalWrite(RELAY_PIN, HIGH);
statopinza = PINZA_APERTA;
}
break;
case PINZA_APERTA:

if (chiudi=HIGH) 
{
digitalWrite(RELAY_PIN, LOW);
statopinza =PINZA_CHIUSA;
}    
break;

  }
}

How are your switches wired?

int apri;
int chiudi;  
apri=digitalRead(BUTTON); 
chiudi=digitalRead(BUTTON1);

Why do you feel it necessary to separate the declaration from the initialization?

if(apri=HIGH)

Most people find that == (the equality comparison operator) works better than = (the assignment operator) in an if statement.

Hy Pauls,
many many many thanks. I'm starting to work with Arduino and i'm non expert. thanks to your suggestion (==) now is perfectly running.
About to separate the declaration from the initialization, i just copied an example found on the web: is that wrong?
Many thanks again.
Andy.

is that wrong?

It isn't right or wrong. It is unnecessary. Keeping the declaration and initialization together makes it clear what type of variable is being used, and uses fewer lines.

int apri = digitalRead(BUTTON); 
int chiudi = digitalRead(BUTTON1);

Hy Pauls,
you mean is just a question of clarity!
Thanks again for your help.
Andy