/* Adjustable Load David Johnson-Davies - www.technoblogy.com - 24th March 2016 ATtiny84 @ 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/ */ // Seven-segment definitions const int charArrayLen = 12; char charArray[] = { // ABCDEFG Segments 0b1111110, // 0 0b0110000, // 1 0b1101101, // 2 0b1111001, // 3 0b0110011, // 4 0b1011011, // 5 0b1011111, // 6 0b1110000, // 7 0b1111111, // 8 0b1111011, // 9 0b0000000, // 10 Space 0b0000001 // 11 Dash }; const int Dash = 11; const int Space = 10; const int Ndigits = 3; // Number of digits volatile int Current = 0; // Current in mA volatile unsigned long Charge = 0; // Charge in mA-seconds volatile char Buffer[] = {Dash, Dash, Dash}; int digit = 0; int DP = -1; // Decimal point position 0 or 1 // Pin assignments char Digits[] = {PIN_B0, PIN_B1, PIN_B2}; // Display multiplexer ********************************************** void DisplayNextDigit() { static int LastReading; DDRB = 0; // Make all digits inputs digit = (digit+1) % (Ndigits+1); if (digit < Ndigits) { char segs = charArray[Buffer[digit]]; if (digit == DP) { // Decimal point DDRB = DDRB | 0x04; PORTB = PORTB & 0xFB; } PORTA = ~segs & 0x7F; // Mask out PA7 for ADC DDRA = segs & 0x7F; DDRB = DDRB | 1<=10) { Display(Current/10, 0); LastReading = Current; } } } } // Display a three digit decimal number with decimal point void Display (int number, int point) { int blank = false, digit, j=100; if (point != 0) blank = true; for (int d=0; d