simple soft-button issue.
i'm sorry if little stupid, i'm totally new (i got board yesterday
)
i'm trying code "soft button". press once circuit turns on (a led in case) press time , turns off... works, partially. of times when hit button led light until release button. if press many times in row produce desired effect , turn on or off led.
)i'm trying code "soft button". press once circuit turns on (a led in case) press time , turns off... works, partially. of times when hit button led light until release button. if press many times in row produce desired effect , turn on or off led.
code: [select]
int flashled = 11;
int statusled = 13;
int actionbtn = 12;
int btnvalue = 0;
int softvalue = 0;
void setup(void) {
// initialize inputs/outputs
pinmode(flashled, output);
pinmode(statusled, output);
pinmode(actionbtn, input);
digitalwrite(statusled, high); // want know when avr done booting
}
void loop(void) {
btnvalue = digitalread(actionbtn);
if (btnvalue == low) {
if (softvalue == 0) {
softvalue = 1;
} else {
softvalue = 0;
}
}
if (softvalue == 1) {
digitalwrite(flashled, high);
} else {
digitalwrite(flashled, low);
}
}
well, adding bit of delay @ bottom of (btnvalue == low) statement seems help. works nicely "static" led. if use flashing led though, turn on, problem same when trying turn off.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > simple soft-button issue.
arduino
Comments
Post a Comment