You are on page 1of 2

/*

Train Whistle Doorbell


Schematic and the deets can be found at petemills.blogspot.com
By Pete Mills
May 2010
ATTiny2313 @ 8MHz internal oscilator
*/

#include <avr/io.h> // defines things like "


PORTB" and "TCCR0" etc
#include <util/delay.h> // delay functions

// 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
}
}
}

You might also like