/* ATtiny85 Bargraph Voltmeter David Johnson-Davies - www.technoblogy.com - 20th December 2015 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/ */ volatile int Display = 0; // Display ********************************************** int Line (int n) { return (1 << n) >> 1; } int Bar (int n) { return ((signed int) 0x8000 >> (15-n))^0xFFFF; } // Interrupt ********************************************** volatile int Row = 0; // Interrupt multiplexes display ISR(TIMER0_COMPA_vect) { int Data; Row = (Row + 1) % 5; DDRB = 0; // Make all pins inputs if (Row == 0) Data = (Display & 0xC0)>>3 | (Display & 0x20)>>4; else if (Row == 1) Data = Display & 0x18; else if (Row == 3) Data = Display>>8 & 0x03; else if (Row == 4) Data = (Display & 0x03) | (Display & 0x04)<<1; else { Display = Bar(ReadADC()/100); return; } // When Row=2 read ADC PORTB = (PORTB | Data) & ~(1<