Digispark ATTiny85 reversed readings?

Hi. I have one of this boards, and looks like the readings are reversed. My code is a very simple one:

#include "DigiKeyboard.h"

void setup() {
  pinmode(0, INPUT);
}

void loop() {
  if (digitalRead(0) == HIGH) {
    DigiKeyboard.print("x");
  }
}

However, if I use the multimeter, I can see that the voltage is 0 when the button is pressed, and 5 when released.

I have a 2.2kO resistor between GND and P0 and the button between 5V and P0.

Is that expected behaviour? and can I reverse it? I need the pin to be 5V when the button is pressed, because there's an led and a 220O resistor in series with the button, and I need it to light up when the button is pressed.

Thank you

What on earth are You talking about? My crystal ball and my mind reading is on vacation for the moment.
Please read this link: How to get the best out of this forum - Using Arduino / Project Guidance - Arduino Forum
Please post schematics.......

When the input pin goes low… i.e.pressed when using INPUT_PULLUP - will make the pin go to 0V

then you should reverse the order of led and the button, and flip the LED.

As the subject says: Digispark ATTiny85 reversed readings?

Sorry, I'm not following you. If I'm not wrong, using INPUT_PULLUP will actually set the pin to 5V when on standby, won't it?

Sorry, I'm not following you either. How should I flip the led? that would reverse polarity and as a diode, wouldn't light up, right? currently, is lit when on standby, and turns off when pressing the button.
This is the schematics:

I need to review that because that's impossible to light if the button is not pressed. I might have crossed something.

Sorry, that doesn’t qualify as a schematic or circuit diagram…
No pins or signals are labelled. No supply, or ground pins identified.

Rethink the PULLUP concept

NOTE
The IDE pin assignments are probably not the chip pin numbers.

Hi. Sorry, I just got introduced to tinkercad, which is awesome, but only has UNOs. I've changed my code to:

#include "DigiKeyboard.h"

void setup() {
  pinmode(0, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(0) == LOW) {
    DigiKeyboard.print("x");
  }
}

and rewired my circuit, which was wrong, and now it's kinda working. I say kinda because the led lights up when the button is pressed, and I get HIGH reading when on standby. However, the reading is not low enough when pressing the button. I read a voltage of around 2.2V which is not enough for the board to read it as LOW. I'm thinking either use analogRead and give it a "less than" command.

BTW, you can't monitor these board in the serial monitor, can you?

can you post the tinkercad diagram here?I suspect you’ve put a resistor somewhere in the raring place.

Actually there are no more resistors. I had them in the previous tests, but not with the INPUT_PULLUP.
The schematic with an UNO is this one: Circuit design Copy of Bodacious Uusam-Albar | Tinkercad

I don’t think we can help you with that.
Good luck.

Thank you anyway. I did fix it with the analogRead option. It took some time to figure out because analogRead requires a different value, so basically I declared pin 2 as INPUT_PULLUP, but I needed to do analogRead(1) for that same pin.

INPUT_PULLUP has no direct effect on analogRead().

I wouldn't say that!

If the ATtiny behaves the same as the 328, then INPUT_PULLUP puts a pull-up bias on the pin. If you just need to bias something connected from the pin to ground, such as a LDR, then that is an excellent way to do it.

You don't use analogRead to read a switch though! :roll_eyes:

for the benfit of the Op, here is a pinout of an ATtiny85.........no idea what the Op's drawing is supposed to do.
ATtiny85

Actually, this was for a project I was working on with an Arduino Pro Micro. It's a button box which I required one button to be a key stroke. I thought I couldn't do it so the micro was detected both as a gamepad and a keyboard, so I thought of using the ATTiny just for that button. But later on I discovered that I could actually do it with just the Micro: Pro Micro as a game device + key stroke - #6 by Assamita