|
| 1 | +#include <LEDMatrixDriver.hpp> |
| 2 | + |
| 3 | +// This sketch draw marquee text on your LED matrix using the hardware SPI driver Library by Bartosz Bielawski. |
| 4 | +// Example written 16.06.2017 by Marko Oette, www.oette.info |
| 5 | + |
| 6 | +// Define the ChipSelect pin for the led matrix (Dont use the SS or MISO pin of your Arduino!) |
| 7 | +// Other pins are Arduino specific SPI pins (MOSI=DIN, SCK=CLK of the LEDMatrix) see https://www.arduino.cc/en/Reference/SPI |
| 8 | +const uint8_t LEDMATRIX_CS_PIN = 9; |
| 9 | + |
| 10 | +// Number of 8x8 segments you are connecting |
| 11 | +const int LEDMATRIX_SEGMENTS = 4; |
| 12 | +const int LEDMATRIX_WIDTH = LEDMATRIX_SEGMENTS * 8; |
| 13 | + |
| 14 | +// The LEDMatrixDriver class instance |
| 15 | +LEDMatrixDriver lmd(LEDMATRIX_SEGMENTS, LEDMATRIX_CS_PIN); |
| 16 | + |
| 17 | +// Marquee text |
| 18 | +char text[] = "M IQBAL N"; |
| 19 | + |
| 20 | +// Marquee speed (lower nubmers = faster) |
| 21 | +const int ANIM_DELAY = 30; |
| 22 | + |
| 23 | +void setup() { |
| 24 | + // init the display |
| 25 | + lmd.setEnabled(true); |
| 26 | + lmd.setIntensity(2); // 0 = low, 10 = high |
| 27 | +} |
| 28 | + |
| 29 | +int x=0, y=0; // start top left |
| 30 | + |
| 31 | +// This is the font definition. You can use http://gurgleapps.com/tools/matrix to create your own font or sprites. |
| 32 | +// If you like the font feel free to use it. I created it myself and donate it to the public domain. |
| 33 | +byte font[95][8] = { {0,0,0,0,0,0,0,0}, // SPACE |
| 34 | + {0x10,0x18,0x18,0x18,0x18,0x00,0x18,0x18}, // EXCL |
| 35 | + {0x28,0x28,0x08,0x00,0x00,0x00,0x00,0x00}, // QUOT |
| 36 | + {0x00,0x0a,0x7f,0x14,0x28,0xfe,0x50,0x00}, // # |
| 37 | + {0x10,0x38,0x54,0x70,0x1c,0x54,0x38,0x10}, // $ |
| 38 | + {0x00,0x60,0x66,0x08,0x10,0x66,0x06,0x00}, // % |
| 39 | + {0,0,0,0,0,0,0,0}, // & |
| 40 | + {0x00,0x10,0x18,0x18,0x08,0x00,0x00,0x00}, // ' |
| 41 | + {0x02,0x04,0x08,0x08,0x08,0x08,0x08,0x04}, // ( |
| 42 | + {0x40,0x20,0x10,0x10,0x10,0x10,0x10,0x20}, // ) |
| 43 | + {0x00,0x10,0x54,0x38,0x10,0x38,0x54,0x10}, // * |
| 44 | + {0x00,0x08,0x08,0x08,0x7f,0x08,0x08,0x08}, // + |
| 45 | + {0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x08}, // COMMA |
| 46 | + {0x00,0x00,0x00,0x00,0x7e,0x00,0x00,0x00}, // - |
| 47 | + {0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06}, // DOT |
| 48 | + {0x00,0x04,0x04,0x08,0x10,0x20,0x40,0x40}, // / |
| 49 | + {0x00,0x38,0x44,0x4c,0x54,0x64,0x44,0x38}, // 0 |
| 50 | + {0x04,0x0c,0x14,0x24,0x04,0x04,0x04,0x04}, // 1 |
| 51 | + {0x00,0x30,0x48,0x04,0x04,0x38,0x40,0x7c}, // 2 |
| 52 | + {0x00,0x38,0x04,0x04,0x18,0x04,0x44,0x38}, // 3 |
| 53 | + {0x00,0x04,0x0c,0x14,0x24,0x7e,0x04,0x04}, // 4 |
| 54 | + {0x00,0x7c,0x40,0x40,0x78,0x04,0x04,0x38}, // 5 |
| 55 | + {0x00,0x38,0x40,0x40,0x78,0x44,0x44,0x38}, // 6 |
| 56 | + {0x00,0x7c,0x04,0x04,0x08,0x08,0x10,0x10}, // 7 |
| 57 | + {0x00,0x3c,0x44,0x44,0x38,0x44,0x44,0x78}, // 8 |
| 58 | + {0x00,0x38,0x44,0x44,0x3c,0x04,0x04,0x78}, // 9 |
| 59 | + {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00}, // : |
| 60 | + {0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x08}, // ; |
| 61 | + {0x00,0x10,0x20,0x40,0x80,0x40,0x20,0x10}, // < |
| 62 | + {0x00,0x00,0x7e,0x00,0x00,0xfc,0x00,0x00}, // = |
| 63 | + {0x00,0x08,0x04,0x02,0x01,0x02,0x04,0x08}, // > |
| 64 | + {0x00,0x38,0x44,0x04,0x08,0x10,0x00,0x10}, // ? |
| 65 | + {0x00,0x30,0x48,0xba,0xba,0x84,0x78,0x00}, // @ |
| 66 | + {0x00,0x1c,0x22,0x42,0x42,0x7e,0x42,0x42}, // A |
| 67 | + {0x00,0x78,0x44,0x44,0x78,0x44,0x44,0x7c}, // B |
| 68 | + {0x00,0x3c,0x44,0x40,0x40,0x40,0x44,0x7c}, // C |
| 69 | + {0x00,0x7c,0x42,0x42,0x42,0x42,0x44,0x78}, // D |
| 70 | + {0x00,0x78,0x40,0x40,0x70,0x40,0x40,0x7c}, // E |
| 71 | + {0x00,0x7c,0x40,0x40,0x78,0x40,0x40,0x40}, // F |
| 72 | + {0x00,0x3c,0x40,0x40,0x5c,0x44,0x44,0x78}, // G |
| 73 | + {0x00,0x42,0x42,0x42,0x7e,0x42,0x42,0x42}, // H |
| 74 | + {0x00,0x7c,0x10,0x10,0x10,0x10,0x10,0x7e}, // I |
| 75 | + {0x00,0x7e,0x02,0x02,0x02,0x02,0x04,0x38}, // J |
| 76 | + {0x00,0x44,0x48,0x50,0x60,0x50,0x48,0x44}, // K |
| 77 | + {0x00,0x40,0x40,0x40,0x40,0x40,0x40,0x7c}, // L |
| 78 | + {0x00,0x82,0xc6,0xaa,0x92,0x82,0x82,0x82}, // M |
| 79 | + {0x00,0x42,0x42,0x62,0x52,0x4a,0x46,0x42}, // N |
| 80 | + {0x00,0x3c,0x42,0x42,0x42,0x42,0x44,0x38}, // O |
| 81 | + {0x00,0x78,0x44,0x44,0x48,0x70,0x40,0x40}, // P |
| 82 | + {0x00,0x3c,0x42,0x42,0x52,0x4a,0x44,0x3a}, // Q |
| 83 | + {0x00,0x78,0x44,0x44,0x78,0x50,0x48,0x44}, // R |
| 84 | + {0x00,0x38,0x40,0x40,0x38,0x04,0x04,0x78}, // S |
| 85 | + {0x00,0x7e,0x90,0x10,0x10,0x10,0x10,0x10}, // T |
| 86 | + {0x00,0x42,0x42,0x42,0x42,0x42,0x42,0x3e}, // U |
| 87 | + {0x00,0x42,0x42,0x42,0x42,0x44,0x28,0x10}, // V |
| 88 | + {0x80,0x82,0x82,0x92,0x92,0x92,0x94,0x78}, // W |
| 89 | + {0x00,0x42,0x42,0x24,0x18,0x24,0x42,0x42}, // X |
| 90 | + {0x00,0x44,0x44,0x28,0x10,0x10,0x10,0x10}, // Y |
| 91 | + {0x00,0x7c,0x04,0x08,0x7c,0x20,0x40,0xfe}, // Z |
| 92 | + // (the font does not contain any lower case letters. you can add your own.) |
| 93 | + }; // {}, // |
| 94 | + |
| 95 | + |
| 96 | +void loop() |
| 97 | +{ |
| 98 | + // Draw the text to the current position |
| 99 | + int len = strlen(text); |
| 100 | + drawString(text, len, x, 0); |
| 101 | + // In case you wonder why we don't have to call lmd.clear() in every loop: The font has a opaque (black) background... |
| 102 | + |
| 103 | + // Toggle display of the new framebuffer |
| 104 | + lmd.display(); |
| 105 | + |
| 106 | + // Wait to let the human read the display |
| 107 | + delay(ANIM_DELAY); |
| 108 | + |
| 109 | + // Advance to next coordinate |
| 110 | + if( --x < len * -8 ) { |
| 111 | + x = LEDMATRIX_WIDTH; |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | + |
| 116 | +/** |
| 117 | + * This function draws a string of the given length to the given position. |
| 118 | + */ |
| 119 | +void drawString(char* text, int len, int x, int y ) |
| 120 | +{ |
| 121 | + for( int idx = 0; idx < len; idx ++ ) |
| 122 | + { |
| 123 | + int c = text[idx] - 32; |
| 124 | + |
| 125 | + // stop if char is outside visible area |
| 126 | + if( x + idx * 8 > LEDMATRIX_WIDTH ) |
| 127 | + return; |
| 128 | + |
| 129 | + // only draw if char is visible |
| 130 | + if( 8 + x + idx * 8 > 0 ) |
| 131 | + drawSprite( font[c], x + idx * 8, y, 8, 8 ); |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +/** |
| 136 | + * This draws a sprite to the given position using the width and height supplied (usually 8x8) |
| 137 | + */ |
| 138 | +void drawSprite( byte* sprite, int x, int y, int width, int height ) |
| 139 | +{ |
| 140 | + // The mask is used to get the column bit from the sprite row |
| 141 | + byte mask = B10000000; |
| 142 | + |
| 143 | + for( int iy = 0; iy < height; iy++ ) |
| 144 | + { |
| 145 | + for( int ix = 0; ix < width; ix++ ) |
| 146 | + { |
| 147 | + lmd.setPixel(x + ix, y + iy, (bool)(sprite[iy] & mask )); |
| 148 | + |
| 149 | + // shift the mask by one pixel to the right |
| 150 | + mask = mask >> 1; |
| 151 | + } |
| 152 | + |
| 153 | + // reset column mask |
| 154 | + mask = B10000000; |
| 155 | + } |
| 156 | +} |
0 commit comments