/* Widget Dashboard - see http://www.technoblogy.com/show?2EDJ David Johnson-Davies - www.technoblogy.com - 18th December 2018 ATtiny85 @ 8 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 // ATtiny85 Pins int const data = 1; int const cs = 3; int const clk = 4; // Character set for text - stored in program memory const uint8_t CharMap[107][6] PROGMEM = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, { 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00 }, { 0x00, 0x07, 0x00, 0x07, 0x00, 0x00 }, { 0x14, 0x7F, 0x14, 0x7F, 0x14, 0x00 }, { 0x24, 0x2A, 0x7F, 0x2A, 0x12, 0x00 }, { 0x23, 0x13, 0x08, 0x64, 0x62, 0x00 }, { 0x36, 0x49, 0x56, 0x20, 0x50, 0x00 }, { 0x00, 0x08, 0x07, 0x03, 0x00, 0x00 }, { 0x00, 0x1C, 0x22, 0x41, 0x00, 0x00 }, { 0x00, 0x41, 0x22, 0x1C, 0x00, 0x00 }, { 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 0x00 }, { 0x08, 0x08, 0x3E, 0x08, 0x08, 0x00 }, { 0x00, 0x80, 0x70, 0x30, 0x00, 0x00 }, { 0x08, 0x08, 0x08, 0x08, 0x08, 0x00 }, { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, { 0x20, 0x10, 0x08, 0x04, 0x02, 0x00 }, { 0x3E, 0x51, 0x49, 0x45, 0x3E, 0x00 }, { 0x00, 0x42, 0x7F, 0x40, 0x00, 0x00 }, { 0x72, 0x49, 0x49, 0x49, 0x46, 0x00 }, { 0x21, 0x41, 0x49, 0x4D, 0x33, 0x00 }, { 0x18, 0x14, 0x12, 0x7F, 0x10, 0x00 }, { 0x27, 0x45, 0x45, 0x45, 0x39, 0x00 }, { 0x3C, 0x4A, 0x49, 0x49, 0x31, 0x00 }, { 0x41, 0x21, 0x11, 0x09, 0x07, 0x00 }, { 0x36, 0x49, 0x49, 0x49, 0x36, 0x00 }, { 0x46, 0x49, 0x49, 0x29, 0x1E, 0x00 }, { 0x00, 0x00, 0x14, 0x00, 0x00, 0x00 }, { 0x00, 0x40, 0x34, 0x00, 0x00, 0x00 }, { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, { 0x14, 0x14, 0x14, 0x14, 0x14, 0x00 }, { 0x00, 0x41, 0x22, 0x14, 0x08, 0x00 }, { 0x02, 0x01, 0x59, 0x09, 0x06, 0x00 }, { 0x3E, 0x41, 0x5D, 0x59, 0x4E, 0x00 }, { 0x7C, 0x12, 0x11, 0x12, 0x7C, 0x00 }, { 0x7F, 0x49, 0x49, 0x49, 0x36, 0x00 }, { 0x3E, 0x41, 0x41, 0x41, 0x22, 0x00 }, { 0x7F, 0x41, 0x41, 0x41, 0x3E, 0x00 }, { 0x7F, 0x49, 0x49, 0x49, 0x41, 0x00 }, { 0x7F, 0x09, 0x09, 0x09, 0x01, 0x00 }, { 0x3E, 0x41, 0x41, 0x51, 0x73, 0x00 }, { 0x7F, 0x08, 0x08, 0x08, 0x7F, 0x00 }, { 0x00, 0x41, 0x7F, 0x41, 0x00, 0x00 }, { 0x20, 0x40, 0x41, 0x3F, 0x01, 0x00 }, { 0x7F, 0x08, 0x14, 0x22, 0x41, 0x00 }, { 0x7F, 0x40, 0x40, 0x40, 0x40, 0x00 }, { 0x7F, 0x02, 0x1C, 0x02, 0x7F, 0x00 }, { 0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00 }, { 0x3E, 0x41, 0x41, 0x41, 0x3E, 0x00 }, { 0x7F, 0x09, 0x09, 0x09, 0x06, 0x00 }, { 0x3E, 0x41, 0x51, 0x21, 0x5E, 0x00 }, { 0x7F, 0x09, 0x19, 0x29, 0x46, 0x00 }, { 0x26, 0x49, 0x49, 0x49, 0x32, 0x00 }, { 0x03, 0x01, 0x7F, 0x01, 0x03, 0x00 }, { 0x3F, 0x40, 0x40, 0x40, 0x3F, 0x00 }, { 0x1F, 0x20, 0x40, 0x20, 0x1F, 0x00 }, { 0x3F, 0x40, 0x38, 0x40, 0x3F, 0x00 }, { 0x63, 0x14, 0x08, 0x14, 0x63, 0x00 }, { 0x03, 0x04, 0x78, 0x04, 0x03, 0x00 }, { 0x61, 0x59, 0x49, 0x4D, 0x43, 0x00 }, { 0x00, 0x7F, 0x41, 0x41, 0x41, 0x00 }, { 0x02, 0x04, 0x08, 0x10, 0x20, 0x00 }, { 0x00, 0x41, 0x41, 0x41, 0x7F, 0x00 }, { 0x04, 0x02, 0x01, 0x02, 0x04, 0x00 }, { 0x40, 0x40, 0x40, 0x40, 0x40, 0x00 }, { 0x00, 0x03, 0x07, 0x08, 0x00, 0x00 }, { 0x20, 0x54, 0x54, 0x78, 0x40, 0x00 }, { 0x7F, 0x28, 0x44, 0x44, 0x38, 0x00 }, { 0x38, 0x44, 0x44, 0x44, 0x28, 0x00 }, { 0x38, 0x44, 0x44, 0x28, 0x7F, 0x00 }, { 0x38, 0x54, 0x54, 0x54, 0x18, 0x00 }, { 0x00, 0x08, 0x7E, 0x09, 0x02, 0x00 }, { 0x18, 0xA4, 0xA4, 0x9C, 0x78, 0x00 }, { 0x7F, 0x08, 0x04, 0x04, 0x78, 0x00 }, { 0x00, 0x44, 0x7D, 0x40, 0x00, 0x00 }, { 0x20, 0x40, 0x40, 0x3D, 0x00, 0x00 }, { 0x7F, 0x10, 0x28, 0x44, 0x00, 0x00 }, { 0x00, 0x41, 0x7F, 0x40, 0x00, 0x00 }, { 0x7C, 0x04, 0x78, 0x04, 0x78, 0x00 }, { 0x7C, 0x08, 0x04, 0x04, 0x78, 0x00 }, { 0x38, 0x44, 0x44, 0x44, 0x38, 0x00 }, { 0xFC, 0x18, 0x24, 0x24, 0x18, 0x00 }, { 0x18, 0x24, 0x24, 0x18, 0xFC, 0x00 }, { 0x7C, 0x08, 0x04, 0x04, 0x08, 0x00 }, { 0x48, 0x54, 0x54, 0x54, 0x24, 0x00 }, { 0x04, 0x04, 0x3F, 0x44, 0x24, 0x00 }, { 0x3C, 0x40, 0x40, 0x20, 0x7C, 0x00 }, { 0x1C, 0x20, 0x40, 0x20, 0x1C, 0x00 }, { 0x3C, 0x40, 0x30, 0x40, 0x3C, 0x00 }, { 0x44, 0x28, 0x10, 0x28, 0x44, 0x00 }, { 0x4C, 0x90, 0x90, 0x90, 0x7C, 0x00 }, { 0x44, 0x64, 0x54, 0x4C, 0x44, 0x00 }, { 0x00, 0x08, 0x36, 0x41, 0x00, 0x00 }, { 0x00, 0x00, 0x77, 0x00, 0x00, 0x00 }, { 0x00, 0x41, 0x36, 0x08, 0x00, 0x00 }, { 0x02, 0x01, 0x02, 0x04, 0x02, 0x00 }, { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 }, { 0x38, 0x44, 0x44, 0x38, 0x00, 0x00 }, // Tiny digits 4x5 { 0x00, 0x08, 0x7C, 0x00, 0x00, 0x00 }, { 0x48, 0x64, 0x54, 0x48, 0x00, 0x00 }, { 0x28, 0x44, 0x54, 0x28, 0x00, 0x00 }, { 0x1C, 0x10, 0x78, 0x10, 0x00, 0x00 }, { 0x5C, 0x54, 0x54, 0x24, 0x00, 0x00 }, { 0x38, 0x54, 0x54, 0x20, 0x00, 0x00 }, { 0x44, 0x24, 0x14, 0x0C, 0x00, 0x00 }, { 0x28, 0x54, 0x54, 0x28, 0x00, 0x00 }, { 0x08, 0x14, 0x14, 0x78, 0x00, 0x00 }, { 0x00, 0x06, 0x09, 0x06, 0x00, 0x00 } // degree symbol }; const int Degree = 138; const int Tiny = 128; // OLED 96x64 colour display ********************************************** // Initialisation sequence for OLED module int const InitLen = 6; const unsigned char Init[InitLen] PROGMEM = { 0xA0, // Driver remap and colour depth 0x22, // COM split, flip horizontal 0xA8, 0x3F, // Multiplex 0xAD, 0x8E, // External supply }; // Send a byte to the display void Send (uint8_t d) { for (uint8_t bit = 0x80; bit; bit >>= 1) { PINB = 1<>1; } uint8_t on = (7-r)*Scale; while ((bits & 1) != 0) {r++; bits = bits>>1; } uint8_t off = (7-r)*Scale+1; for (int i=0; i>1&1)+0x1F*(colour>>3&1); ForeB=0x3F*(colour>>2&1); } // Draws a titled frame and sets x and y to frame origin void Frame (PGM_P title, uint8_t *x, uint8_t *y) { *x = (Widget%2) * 48; *y = 32 - (Widget/2) * 32; uint8_t shade; if (((Widget+1)/2)%2) shade = 0x04; else shade = 0x0C; BackR=BackG=BackB=ForeR=ForeG=ForeB=shade; DrawRect(1, *x, *y, (*x)+47, (*y)+31); ForeR=ForeG=ForeB=0x3F; Scale=1; MoveTo((*x)+1, (*y)+23); PlotText(title); Widget=(Widget+1) & 3; } // Plot integer with suffix void PlotInteger (int number, PGM_P suffix) { uint8_t len = strnlen_P(suffix, 4); boolean dig = false; unsigned int j=1000; for (int i=0; i>9)+24+x0, (y>>9)+1+y0); x = x + ((y>>9) * Delta); y = y - ((x>>9) * Delta); DrawTo((x>>9)+24+x0, (y>>9)+1+y0); if (i == value) { MoveTo((x>>9)+24+x0, (y>>9)+1+y0); DrawTo(24+x0, 1+y0); } if (i%20 == 0) { MoveTo((x>>9)+24+x0, (y>>9)+1+y0); DrawTo((x>>9)-(x>>11)+24+x0, (y>>9)-(y>>11)+1+y0); } } // Plot tiny digits 0 to 5 MoveTo(3+x0,0+y0); PlotChar(Tiny+0); MoveTo(5+x0,9+y0); PlotChar(Tiny+1); MoveTo(14+x0,16+y0); PlotChar(Tiny+2); MoveTo(30+x0,16+y0); PlotChar(Tiny+3); MoveTo(39+x0,9+y0); PlotChar(Tiny+4); MoveTo(42+x0,0+y0); PlotChar(Tiny+5); } // Setup ********************************************** void setup() { Wire.begin(); // Define pins DDRB = 1<