/* Continuity Tester David Johnson-Davies - www.technoblogy.com - 18th November 2017 ATtiny85 @ 1 MHz (internal oscillator; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include #include const int LED = 2; const int Reference = 0; // AIN0 const int Probe = 1; // AIN1 const int Speaker = 4; const unsigned long Timeout = (unsigned long)60*1000; // One minute volatile unsigned long Time; // Pin change interrupt service routine - resets sleep timer ISR (PCINT0_vect) { Time = millis(); } void Beep () { TCCR1 = TCCR1 | 3; // Counter = clock/4 } void NoBeep () { TCCR1 = TCCR1 & ~3; // Counter stopped } void setup () { pinMode(Reference, INPUT_PULLUP); pinMode(Probe, INPUT_PULLUP); pinMode(LED, OUTPUT); pinMode(Speaker, OUTPUT); pinMode(3, OUTPUT); // Don't leave floating // Setup beep TCCR1 = 1<>ACO & 1; if (Sense) Beep(); else NoBeep(); // Go to sleep? if (millis() - Time > Timeout) { digitalWrite(LED, false); // LED off pinMode(Reference, INPUT); // Turn off pullup to save power sleep_enable(); sleep_cpu(); // Carry on here when we wake up pinMode(Reference, INPUT_PULLUP); digitalWrite(LED, true); // LED on } }