#include int main(void) { DDRA = 0b10000000; //Data direction register, "0b" means that everything that follows is binary; 0 is input into, 1 is output out of microcontroller. Start counting from the right. PORTA = 0b00001000; //Setting PA3 high to set/initialize the pull-up resistor in Attiny44. while(1){ /* The conditions in the "if" statement: When button is not pressed (the switch is not closed), the 5V of supply voltage of the ATTINY44 will flow through the pull-up resistor inside the ATTINY44, and PA3 will be at 5V and a "high" state (1). When button is pressed (the switch is closed), PA3 will be connected to ground and it will be at 0V or a "low" state (0). When button is pressed, PINA = 0bxxxx0xxx; when button is not pressed, PINA = 0bxxxx1xxx. x stands for the state of other pins, which could either be 0 or 1. If let's say PINA = 0b00000000 when button is pressed and PINA = 0b00001000 when button is not pressed, then when button is pressed, (0b00000000 & 0b00001000) will give us a 0 because they have nothing in common. When button is not pressed, (0b00001000 & 0b00001000) will give us a non-zero number. In this case, the "and" operation will return an 8 because they have "1000" in common and 2^3 = 8. So when button is not pressed, the return value of the "and" operation is 8, and 8 is true, so statement in "if" - "PORTA = 0b00001000" - will be carried out and the LED is off, because PA7 is low. When button is pressed, the return value of the "and" operation is 0, and 0 is false. So the "else" statement "PORTA = 0b10001000" will be carried out and the LED is on, because PA7 is high. */ if (PINA & 0b00001000){ //PINA is the register that is read to detect input high or low. PORTA = 0b00001000; //We write to PORTA for output or to set pull-up resistor. Keeping the pull-up resistor high, now turn off LED by setting PA7 low } else{ PORTA = 0b10001000; //Keeping the pull-up resistor high, now turn on LED by setting PA7 high } } return (0); }