Professional Documents
Culture Documents
Main
Main
// variables
// function prototypes
void setup(void);
// functions
void setup(void){
// port config
DDRB &= ~(1<<2); // set P
B2 to "0" for input
DDRB |= ((1<<0) | (1<<1)); // set portB bits 0..1 t
o 1 for output
PORTB &= ~((1<<0) | (1<<1)); // set the outputs low
}
int main(void){
setup();
while(1){
if(bit_is_set(PINB,2)){
_delay_ms(3000);
// let the doorbell ring for a bit
PORTB |= ((1<<0) | (1<<1));
// toot one and turn on led
_delay_ms(500);
PORTB &= ~((1<<0) | (1<<1));
// stop toot and turn off led
_delay_ms(300);
PORTB |= ((1<<0) | (1<<1));
// toot two and turn on led
_delay_ms(1000);
PORTB &= ~((1<<0) | (1<<1));
// stop toot and turn off led
_delay_ms(5000);
// blank out repetitions for a bit
}
}
}