I'm trying to write a simple program in C that turns a row of LED lights OFF when I press a button. I'm very new to both embedded devices and using bitwise operators and I can't figure out what I'm doing wrong.
I'm using a Romeo board with an Amega328p which is hooked up to an I/O kit board where the pins connect to the LEDs and push buttons seperately.
The pins have DDRx PORTx and PINx settings.
I've connected pins D2-D7 to JP3_1-6 for the LEDs (I can see this part works)
I've connected pin D10 (PB2) to JP2_5 for the button (problem part)
I've connect the GNDs & VCCs on both boards to each other.
Here is my code:
void main()
{
DDRD = 0b11111100; // open all registries to be used
PORTD = 0b11111100; // set all LEDs ON to start
DDRB = 0b00000000; // set as input
PORTB = 0b00000100; // set PB2 pull up resistors
if((PINB & 0b00000100)==0) // if buttons pressed
{
PORTD = 0b00000000; // turn all lights off
}
}
When I push the button nothing happens. I don't think it's the board because it doesn't matter what switch I use.
Any help or direction in solving this would be appreciated. I think it's code and not how I'm hooking things up but I'm a newbie so I could be wrong.