/*
 * ledbutton.c
 *
 * Based on Dorinna Rajanen code
 * Author : Eikka A   */

#include <avr/io.h>

int main(void) {
	DDRB |= (1<<PB2);  /* data direction register for pin PB2 defined as output, DDRA:  1000 0000 
						This pin PA7 corresponds to the led */
	DDRA &= ~(1<<PA7);  /* DDRA is defined as input for the pin PB2, DDRA will still be: 1000 0000 */
						
	
	while (1) {    /* eternal loop , as long as the board is connected to power */
		
		if (PINA & (1<<PA7))   /* it means that when PINA3 register is 1 and PA3 is 1,  the command after if () will be executed; 
								otherwise the else command will be executed;
								Thus, expression () is true only when PA3 value (which is triggered by button press) is 1.
								According to schematic, PINA for PA3 is 1 when button is not pressed;
								When button is pressed, button is connected to ground, so PA3 will have 0; 
								so the else command will be executed when button is pressed;  */
					
			PORTB = (0<<PB2);   /*led is off; PORTB2 will have value 0 ;
								the led is off when button is not pressed*/
					
		else 
			
			PORTA = (1<<PB2);   /*led is on; PORTB2 will have value 1;
								when button is pressed */
			}
}
