#define DISPLAY_WIDTH 4 #define DISPLAY_HEIGHT 5 unsigned long characterMap[3]; // set up a character in the characterMap void Chr(char theChar, unsigned long value) { characterMap[theChar - 32] = value; } // The offset of our string in the display int offset = 0; unsigned long lastMillis = 0; unsigned long currentMillis = 0; unsigned int timeout; int length = sizeof("FAV"); // render the string on the given offset void renderString(char *theString, int offset) { int index = 0; while (theString[index]) { renderCharacter(theString[index], offset - index * (DISPLAY_WIDTH + 1)); index++; } } // render a character on the given offset void renderCharacter(char theChar, int charOffset) { if (charOffset <= -DISPLAY_WIDTH || charOffset > DISPLAY_WIDTH) { // off the 'screen' nothing to do return; } unsigned long graphic = characterMap[theChar - 32]; for (byte y = 0; y < DISPLAY_HEIGHT; y++) { for (byte x = 0; x < DISPLAY_WIDTH; x++) { setPixel(3 - x + charOffset, y, graphic & 0x1); graphic = graphic >> 1; } } } // light a pixel at the given coordinates void setPixel(byte x, byte y, boolean ledStatus) { if (x >= 0 && x < DISPLAY_WIDTH) { if (y <= x) { x++; } setLed(y, x, ledStatus); } } // turn on the pins to light a LED void setLed(byte vin, byte gnd, boolean ledStatus) { delay(1); pinMode(0, INPUT); pinMode(1, INPUT); pinMode(2, INPUT); pinMode(3, INPUT); pinMode(4, INPUT); if(!ledStatus) return; pinMode(vin, OUTPUT); pinMode(gnd, OUTPUT); digitalWrite(vin, HIGH); digitalWrite(gnd, LOW); } // runs at start void setup() { // set up render map // Rows: 1---2---3---4---5--- Chr('A', 0b10011001111110010110); Chr('B', 0b01111001011110010111); Chr('F', 0b00010001011100011111); // how long to wait between shifting the display timeout = 1000 / 12; } // loops continuously void loop() { currentMillis = millis(); setLed(1,1, 0x1); // renderString("FAB", offset); // if (currentMillis - lastMillis > timeout) { // lastMillis = currentMillis; // // shift string over one "pixel" // offset++; // // if it's past the length of the string, start over from the beginning // if (offset > length * (DISPLAY_WIDTH + 1)) { // offset = -DISPLAY_WIDTH; // } // } }