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.
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:
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.
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.
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.
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