/* LED Probe (ATtiny85 Version) - see http://www.technoblogy.com/show?53Z6 David Johnson-Davies - www.technoblogy.com - 20th May 2025 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 RedLED = PIN_PB3; const int GreenLED = PIN_PB4; const int Output = PIN_PB0; const int Input = PIN_PB2; const int Lead = PIN_PB1; const unsigned long Timeout = (unsigned long)60*1000; // One minute volatile unsigned long Time; // INT0 interrupt service routine - wakes up ISR (INT0_vect) { } void setup () { pinMode(Lead, OUTPUT); pinMode(Output, OUTPUT); pinMode(RedLED, OUTPUT); pinMode(GreenLED, OUTPUT); set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Start running Time = millis(); } // Target ADC values const int Max = 1007; // 2.95V const int High = 768; // 2.25V const int Low = 256; // 0.75V const int Min = 17; // 0.05V int Flash = 0; void loop() { uint16_t v1, v2; // The two analogue readings do { // Probe positive digitalWrite(Lead, LOW); digitalWrite(Output, HIGH); delay(10); v1 = analogRead(A1); // Probe negative digitalWrite(Lead, HIGH); digitalWrite(Output, LOW); delay(10); v2 = analogRead(A1); // Display result if (v1 > Max && v2 < Min) { digitalWrite(RedLED, LOW); digitalWrite(GreenLED, LOW); // Open circuit } else if (v1 < Low && v2 > High) { digitalWrite(RedLED, HIGH); digitalWrite(GreenLED, HIGH); // Short circuit Time = millis(); } else if (v1 > Low && v1 < Max && v2 < Min) { digitalWrite(RedLED, HIGH); digitalWrite(GreenLED, LOW); // Probe to LED + Time = millis(); } else if (v1 > Max && v2 > Min && v2 < High) { digitalWrite(RedLED, LOW); digitalWrite(GreenLED, HIGH); // Probe to LED - Time = millis(); } else { int state = (Flash & 0b1000) ? HIGH : LOW; digitalWrite(RedLED, state); digitalWrite(GreenLED, state); // Error } Flash++; } while (millis() - Time < Timeout); // Go to sleep? // Power saving ADCSRA = ADCSRA & ~(1<