/* Scrolling Text Display PCB - see http://www.technoblogy.com/show?4XB2 David Johnson-Davies - www.technoblogy.com - 16th December 2024 ATtiny85 @ 8 MHz (internal); B.O.D. Enabled (2.7V) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ #include #include const char VersionNumber = '4'; // Displayed with NumLock // EEPROM structure ************************************* const int EndMessageGap = 5; const int MessageSize = 308; // Maximum message size const int UserCharStart = 0; // Address of user-defined characters in EEPROM const int NumUserChars = 26; // Number of user-defined characters const int DataStart = NumUserChars*6; // Start of Data struct in EEPROM struct { uint16_t Ptr; // Pointer to space after last character uint8_t Buffer[MessageSize]; } Data; #if (NumUserChars*6 + MaxMessage > 512) #error "Not enough EEPROM!" #endif // Display ********************************************** // Character set const uint8_t CharMap[96][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, 0xFF }, }; // User-definable characters defaults const uint8_t DefaultMap[26][6] PROGMEM = { { 0x94, 0x55, 0xFE, 0x55, 0x94, 0x00 }, // Ant { 0x92, 0x55, 0x3D, 0x55, 0x92, 0x00 }, // Boy { 0x04, 0x6B, 0xFE, 0xEB, 0x84, 0x60 }, // Cat { 0x10, 0xA8, 0x60, 0x20, 0x60, 0x90 }, // Dog { 0x2C, 0x76, 0xEF, 0xF7, 0x6E, 0x34 }, // Egg { 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 0x00 }, // Face { 0x92, 0xD5, 0xFD, 0xD5, 0x92, 0x00 }, // Girl { 0xF8, 0x04, 0x12, 0xD2, 0x04, 0xFE }, // House { 0xAA, 0xC5, 0xFE, 0xC5, 0xAA, 0x00 }, // Island { 0x7B, 0x57, 0x22, 0x75, 0x6F, 0x00 }, // Jigsaw puzzle { 0x00, 0x06, 0xF9, 0x56, 0x00, 0x00 }, // Key { 0xFE, 0xF1, 0x91, 0xF1, 0xFE, 0x00 }, // Lock { 0x12, 0xD5, 0x3D, 0xD5, 0x12, 0xE0 }, // Man { 0x24, 0x24, 0x75, 0xAE, 0x24, 0x24 }, // National Rail Logo { 0xAE, 0x7B, 0xFF, 0x7B, 0xAE, 0x00 }, // Octopus { 0x22, 0xF7, 0x7D, 0xFF, 0x10, 0x20 }, // Penguin { 0x3F, 0xEE, 0xDF, 0xEE, 0x3F, 0x00 }, // Queen { 0x17, 0xD5, 0x3F, 0xD5, 0x17, 0x00 }, // Robot { 0x0C, 0x1A, 0xFB, 0x1A, 0x0C, 0x00 }, // Sign { 0x08, 0x1C, 0x2A, 0x2A, 0x1C, 0x08 }, // Tube Roundel { 0x0C, 0x0E, 0x7F, 0x8E, 0x4C, 0x00 }, // Umbrella { 0x7C, 0xC2, 0x5A, 0x5A, 0xC2, 0x5A }, // V Train left { 0x5A, 0xC2, 0x7A, 0x7A, 0xC2, 0x5A }, // W Train middle { 0x5A, 0xC2, 0x5A, 0x5A, 0xC2, 0x7C }, // X Train right { 0x78, 0xC4, 0x42, 0x4A, 0xC2, 0x42 }, // Y Train engine { 0x42, 0xC2, 0x4A, 0x42, 0xC4, 0x78 }, // Z Train end }; // Constants const int Displays = 4; const int CharWidth = 6; const int CharHeight = 7; const int nColumns = 6; const int ColWidth = 2; const uint8_t DisplayAddrs[Displays] PROGMEM = {112, 113, 114, 115}; uint8_t ReverseByte (uint8_t x) { x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); return x; } void DisplaySetup (int addr) { Wire.beginTransmission(addr); Wire.write(0x21); Wire.endTransmission(); } void DisplayOn (int addr, bool on) { Wire.beginTransmission(addr); Wire.write(0x80 + on); Wire.endTransmission(); } // Brightness from 1 to 15 void DisplayBrightness (int addr, int bri) { Wire.beginTransmission(addr); Wire.write(0xe0 + bri); Wire.endTransmission(); } const int Brightness = 2; // Keyboard ********************************************** const int ClockPin = 4; // PB4 = D+ const int DataPin = 1; // PB1 = D- const int ADCPin = 3; // PB3 const int KeymapSize = 0x84; // Control codes const int Escape = 27; const int NumLock = 28; const int ScrollLock = 29; const int CapsLock = 30; const uint8_t Keymap[] PROGMEM = // Without shift " \031 \025\023\021\022\034 \032\030\026\024\011` q1 zsaw2 " // 0x00 to 0x1F " cxde43 vftr5 nbhgy6 mju78 " // 0x20 to 0x3F " ,kio09 ./l;p- \' [= \036 \015] \\ " // 0x40 to 0x5F " \010 1 47 0.2568\033\034 +3-*9\035 \027" // 0x60 to 0x83 // With shift " \031 \025\023\021\022\034 \032\030\026\024\011~ Q! ZSAW@ " // 0x00 to 0x1F " CXDE$# VFTR% NBHGY^ MJU&* " // 0x20 to 0x3F " ?L:P_ \" {+ \036 \015} | " // 0x40 to 0x5F " \010 1 47 0.2568\033\034 +3-*9\035 \027"; // 0x60 to 0x83 ISR(PCINT0_vect) { static bool Break = 0, Modifier = 0, Shift = 0, Alt = 0, Ctrl = 0; static int ScanCode = 0, ScanBit = 1; if (PINB & 1<> 1; ScanCode = 0, ScanBit = 1; if (s == 0xAA) return; // BAT completion code if (s == 0xF0) { Break = 1; return; } if (s == 0xE0) { Modifier = 1; return; } if (Modifier && Break) { if (s == 0x11) Alt = 0; // Right Alt released if (s == 0x14) Ctrl = 0; // Right Ctrl released Break = 0; Modifier = 0; return; } else if (Modifier) { if (s == 0x11) Alt = 1; // Right Alt pressed if (s == 0x14) Ctrl = 1; // Right Ctrl pressed Modifier = 0; return; } else if (Break) { if ((s == 0x12) || (s == 0x59)) Shift = 0; // Left or Right Shift released if (s == 0x11) Alt = 0; // Left Alt released if (s == 0x14) Ctrl = 0; // Left Ctrl released Break = 0; Modifier = 0; return; } if ((s == 0x12) || (s == 0x59)) { Shift = 1; return; } // Left or Right Shift pressed if (s == 0x11) { Alt = 1; return; } // Left Alt pressed if (s == 0x14) { Ctrl = 1; return; } // Left Ctrl pressed uint8_t c = pgm_read_byte(&Keymap[s + KeymapSize*Shift]); if (c == 32 && s != 0x29) return; ProcessKey(c, Ctrl, Alt); return; } // Processing keys ********************************************** enum modes { Display, Edit, Design }; volatile uint8_t Mode = Display; volatile int Scroll = 0; volatile int MessageChars = MessageSize + EndMessageGap; volatile uint8_t DesignChar = 0; volatile uint8_t DesignBit = 0; volatile uint8_t soft[6]; volatile bool NeedsSaving; void SaveColumn (bool val) { uint8_t col = DesignBit%6; uint8_t bit = DesignBit/6; soft[col] = (soft[col] & ~(1< 5) Scroll = 6 * (Data.Ptr - 5); else Scroll = 0; } void EditModeMessageChars () { MessageChars = MessageSize + EndMessageGap; } void DisplayModeMessageChars () { MessageChars = Data.Ptr + EndMessageGap; } void RestoreDefaults () { // Copy default user-defined characters for (int i=0; i< NumUserChars; i++) { for (int c=0; c<6; c++) { EEPROM.write(i*6 + c, pgm_read_byte(&DefaultMap[i][c])); } } } void ProcessKey (uint8_t c, bool ctrl, bool alt) { // Design mode *************************************************************** if (Mode == Design) { if (c == Escape) { Mode = Edit; ScrollMessage(); EditModeMessageChars(); return; } if (c == '\r') { // Return key goes to display mode Mode = Display; DisplayModeMessageChars(); Scroll = 0; return; } if (c == 8 && DesignBit > 0) { DesignBit--; SaveColumn(0); return; } if ((c == '.' || c == '/' || c == ' ') && DesignBit < 48) { bool val = (c == '.'); SaveColumn(val); DesignBit++; return; } // Display mode *************************************************************** } else if (Mode == Display) { if (c == '\r') return; // Ignore Return if (c == Escape) { // Escape key goes to edit mode Mode = Edit; ScrollMessage(); EditModeMessageChars(); return; } if (c == ScrollLock) { RestoreDefaults(); return; } // Edit mode *************************************************************** } else if (Mode == Edit) { if (c == Escape) return; // Ignore Escape if (c == '\r') { // Return key goes to display mode Mode = Display; DisplayModeMessageChars(); Scroll = 0; return; } if (c == 9) { // Tab key - clear page for (int i=0; i 0) { if (Data.Ptr <= 5) Scroll = Scroll - 6; Data.Ptr--; Data.Buffer[Data.Ptr] = ' '; NeedsSaving = true; } } else if (Data.Ptr < MessageSize) { if (ctrl) { if (c >= 'A' && c <= 'Z') { Mode = Design; DesignChar = c - 'A'; DesignBit = 0; for (int col=0; col<6; col++) { soft[col] = 0; EEPROM.write(DesignChar*6 + col, 0); // Clear user-defined character } c = DesignChar + 'a'; } if (!(c >= 'a' && c <= 'z')) return; c = c - 'a'; } Data.Buffer[Data.Ptr++] = c + 128*alt; NeedsSaving = true; } ScrollMessage(); return; } } void SetupKeyboard() { PORTB = PORTB | 1<= MessageChars - EndMessageGap) c = 32; else c = Data.Buffer[nchar]; if ((c & 0x7F) < 32) segs = ReverseByte(EEPROM.read((c & 0x7F)*6 + cchar)); // User-defined character else segs = ReverseByte(pgm_read_byte(&CharMap[(c & 0x7F)-32][cchar])); // Normal character if (c >= 128) segs = segs ^ 0xff; // Inverse video character Wire.beginTransmission(addr); Wire.write(col<<1); Wire.write(segs>>1 | segs<<7); Wire.endTransmission(); } } delay((1023-analogRead(ADCPin))>>3); if (NeedsSaving) { EEPROM.put(DataStart, Data); NeedsSaving = false; } if (Mode == Display) Scroll = (Scroll+1) % (MessageChars*6); }