Why is this doing nothing (button)

int one = digitalRead(2);

void setup()
{
pinMode(2, INPUT);
}

void loop()
{
if (one != LOW) {
Serial.println(one);
}
delay(5); // Delay a little bit to improve simulation performance
}

ardino1.PNG

Because the value of one will never change. In the initialization of the variable, you're just setting it to the state of the pin at that time. It's not going to automatically update for you. You need to call digitalRead() every time you want to check the state of the pin.

Several ways you could fix that;

if (digitalRead(2) != LOW)

if (digitalRead(2) == HIGH)

if (digitalRead(2))

or declare one() as a macro;

#define one() digitalRead(2)

then

if (one() != LOW) and so on, or declare an inline function,

inline byte one() {return digitalRead(2);}

Thank you pert, very cool!