/*********************************************************** * _____ +-----\/-----+ * * RESET PB5 1 --|o |-- 8 Vcc * * | | * * XALT1 PB3 2 --| |-- 7 PB2 SCK SCL * * | ATTINY85 | * * XALT2 PB4 3 --| |-- 6 PB1 MISO DO * * | | * * GND 4 --| |-- 5 PB0 MOSI DI SDA * * +------------+ * * * * compiled with ATtiny Microcontrollers from * * David A. Mellis https://github.com/damellis/attiny * * * ***********************************************************/ #include #include #define PIN_LED PCINT0 // PIN 5 PB0 for debugging, remove later #define PIN_DOORBELL PCINT1 // PIN 6 PB1 #define PIN_BUTTON PCINT2 // PIN 7 PB2 #define PIN_UNUSED_1 PCINT3 // PIN 2 PB3 #define PIN_UNUSED_2 PCINT4 // PIN 3 PB4 //#define PIN_UNUSED_3 PCINT5 // PIN 1 PB5 (Reset, usable only with disabled reset) volatile uint8_t counter=0; volatile uint32_t lastrun; ISR (PCINT0_vect) { //nur bei fallender Flanke reagieren if ((PINB & _BV(PIN_BUTTON)) == 0) { if ((millis() - lastrun) > 30) { counter = counter & 0b00000111; counter++; lastrun = millis(); } } } void goToSleep() { PORTB &= ~_BV(PIN_LED); PORTB &= ~_BV(PIN_DOORBELL); //digitalWrite (PIN_LED, LOW); //digitalWrite (PIN_DOORBELL, LOW); set_sleep_mode(SLEEP_MODE_PWR_DOWN); ADCSRA = 0; // turn off ADC power_all_disable(); // power off ADC, Timer 0 and 1, serial interface sleep_enable(); sleep_cpu(); sleep_disable(); power_all_enable(); // power everything back on } void setup() { lastrun=millis(); pinMode(PIN_LED, OUTPUT); pinMode(PIN_DOORBELL, OUTPUT); pinMode(PIN_BUTTON, INPUT_PULLUP); // for power saving: pinMode(PIN_UNUSED_1, OUTPUT); pinMode(PIN_UNUSED_2, OUTPUT); // pin change interrupt PCMSK |= bit (PIN_BUTTON); GIFR |= bit (PCIF); // clear any outstanding interrupts GIMSK |= bit (PCIE); // enable pin change interrupts // give feedback while debugging // digitalWrite (PIN_x, HIGH); PORTB |= _BV(PIN_LED); delay (1000); // digitalWrite (PIN_x, LOW); PORTB &= ~_BV(PIN_LED); PORTB &= ~_BV(PIN_UNUSED_1); PORTB &= ~_BV(PIN_UNUSED_2); delay(2000); goToSleep(); } void loop() { for (uint8_t i = 0 ; i