how would you use a reverse button with this code

so I found this code on the internet, and i'm wondering if you can use a reverse button with it.

i.e: button unpressed = button pressed button pressed = button unpressed.

here's the code

void setup() {

pinMode(2, INPUT_PULLUP);// define pin two as input for push button
pinMode(10, OUTPUT);// defind pin 10 as output
}

void loop() {

int pusshed = digitalRead(2);// read pin 2 and put the result in the "pusshed" variable
if(pusshed == LOW){
digitalWrite(10, HIGH);// if pusheed is equal LOW, turn the pin 10 HIGH (give it 5v)
}else{
digitalWrite(10, LOW);// else set pin 10 to low or zero volt
}
}

“ button unpressed = button pressed button pressed = button unpressed.”

Say what ? :o


if(pusshed == LOW){

VS

if(pusshed == HIGH){


How do you have ‘your’ switch wired ?

The button is a computer case intrusion button, that’s why its reversed

nsent, would seem possible to just swap the digital Writes

digitalWrite(10, LOW);
}else{
digitalWrite(10, HIGH);

i had to change the if(pusshed == LOW too if(pusshed == HIGH

Hmmm, I would write:

digitalWrite(10, ! digitalRead(2));

Using it as a power button for my pc that has no case, it works fine now!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.