Hi
I'm having a problem with my avr not detecting a button press it seems. The chip is running fine and switch is connected to ground. I'm wondering if the type of switch makes a difference since the one in the image isn't an SPDT.
Hi
I'm having a problem with my avr not detecting a button press it seems. The chip is running fine and switch is connected to ground. I'm wondering if the type of switch makes a difference since the one in the image isn't an SPDT.
Dunno about the AVR, but on a PIC, the port has to be set up for input, and independently, the Pull-Ups have to be enabled by writing a bit to the appropriate register (two independent settings).
The switch then is wired between the port pin and Vss (GND).
PORTD = 1<<7 will affect PORTD pin 7. You have the button on PIN 5
DDRD &= ~(1<<5); // This sets Pin 5 of port D to an input
PORTD |= (1<<5); // This enables the pullup on port D pin 5
button_state = (PIND & (1<<5)); // Read from PIND, not from PORTD... this is a classic AVR mistake
if (button_state == 0)
button is pressed
Also, take a look here: AVR Tutorial: Switch Input and Debounce
If you don't handle bounce, you could easily read many switch presses when you only want to read 1