So I have an assignment that wants me to perform certain code when a button on PD2 is presed.
The problem i'am having right now is i don't really know what to check for neither do i understand the underlying logic.
So this is the code i've come up with thus far.
 DDRD=0x00;   //PORTD pin 0 as input
    PORTD=0x00;
    
    DDRB=0xFF;   //PORTB as output
    PORTB=0x00;
    
    
    while(1){
        if (PIND & (1<<PD2)==1) // check if PD2 is pressed on PIND2
        {
            // modify bits on PORTB here
        }
        
        }
I'm using Atmega328 and running this on AtmelStudio 7
 
                        
This way you should be able to read your inputs every program cycle. But I've not tested this. It's important to use
__no_operation()before reading again PIND.