Coding Global Background
Coding Global

why does my super simple script work in reverse?

Archived a year ago
3 messages
2 members
Created a year ago
Updated a year ago
Open in Discord
W
WatermelonPet

Playing Custom Status

Verified
for context im using an arduino nano powering a laser emitter whenever digitalWrite happens
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

void setup() {
 pinMode(2,OUTPUT);
 pinMode(3,INPUT);

}

void loop() {
    if (digitalRead(3) == HIGH) digitalWrite(2,HIGH);
    else 
    {
    digitalWrite(2,LOW);
  }

}
Now, the problem is whenever i press the button (digitalRead high) it turns the light off rather than on anyone know why this could be happening?

Replies (2)