STATE MACHINE


hy everybody,
many in advance @ tell me i'm wrong.
i want control led, button switch on , button1 switch off. if run code led still on , no control buttons.
thanks again.
andy.
code: [select]

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 switches wired?

code: [select]
int apri;
int chiudi; 
apri=digitalread(button);
chiudi=digitalread(button1);

why feel necessary separate declaration initialization?

code: [select]
if(apri=high)
most people find == (the equality comparison operator) works better = (the assignment operator) in if statement.


Arduino Forum > Using Arduino > Programming Questions > STATE MACHINE


arduino

Comments

Popular posts from this blog

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

How to format a Get Request

avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0x62