Forked LEDMatrix and added horizontal scrolling

Fork of LEDMatrix by Yihui Xiong

Committer:
Bobty
Date:
Thu Jan 14 16:52:04 2016 +0000
Revision:
3:1e06e89bc0c9
Parent:
2:cd2da920cf98
Child:
4:40d4afefcd74
Added flashing effect

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yihui 0:13728deac7a7 1 /**
yihui 0:13728deac7a7 2 * LED Matrix library for http://www.seeedstudio.com/depot/ultrathin-16x32-red-led-matrix-panel-p-1582.html
yihui 0:13728deac7a7 3 * The LED Matrix panel has 32x16 pixels. Several panel can be combined together as a large screen.
yihui 0:13728deac7a7 4 *
yihui 0:13728deac7a7 5 * Coordinate & Connection (mbed -> panel 0 -> panel 1 -> ...)
yihui 0:13728deac7a7 6 * (0, 0) (0, 0)
yihui 0:13728deac7a7 7 * +--------+--------+--------+ +--------+--------+
yihui 0:13728deac7a7 8 * | 5 | 3 | 1 | | 1 | 0 |
yihui 0:13728deac7a7 9 * | | | | | | |<----- mbed
yihui 0:13728deac7a7 10 * +--------+--------+--------+ +--------+--------+
yihui 0:13728deac7a7 11 * | 4 | 2 | 0 | (64, 16)
yihui 0:13728deac7a7 12 * | | | |<----- mbed
yihui 0:13728deac7a7 13 * +--------+--------+--------+
yihui 0:13728deac7a7 14 * (96, 32)
yihui 0:13728deac7a7 15 * Copyright (c) 2013 Seeed Technology Inc.
yihui 0:13728deac7a7 16 * @auther Yihui Xiong
yihui 0:13728deac7a7 17 * @date Nov 7, 2013
yihui 0:13728deac7a7 18 * @license Apache
yihui 0:13728deac7a7 19 */
yihui 0:13728deac7a7 20
yihui 0:13728deac7a7 21
yihui 0:13728deac7a7 22 #ifndef __LED_MATRIX_H__
yihui 0:13728deac7a7 23 #define __LED_MATRIX_H__
yihui 0:13728deac7a7 24
yihui 0:13728deac7a7 25 #include "mbed.h"
yihui 0:13728deac7a7 26
Bobty 2:cd2da920cf98 27 const int LED_MATRIX_LEDS_HORIZONTALLY = 32;
Bobty 2:cd2da920cf98 28 const int LED_MATRIX_LEDS_VERTICALLY = 16;
Bobty 3:1e06e89bc0c9 29 const int LED_MATRIX_MAX_LINES = 2;
Bobty 2:cd2da920cf98 30
Bobty 2:cd2da920cf98 31 class LEDMatrix
Bobty 2:cd2da920cf98 32 {
yihui 0:13728deac7a7 33 public:
Bobty 2:cd2da920cf98 34
yihui 0:13728deac7a7 35 LEDMatrix(PinName pinA, PinName pinB, PinName pinC, PinName pinD, PinName pinOE, PinName pinR1, PinName pinSTB, PinName pinCLK);
yihui 0:13728deac7a7 36
yihui 0:13728deac7a7 37 /**
yihui 0:13728deac7a7 38 * set the display's display buffer and number, the buffer's size must be not less than 512 * number / 8 bytes
Bobty 2:cd2da920cf98 39 * @param pDisplayBuf display buffer
yihui 0:13728deac7a7 40 * @param number panels' number
yihui 0:13728deac7a7 41 */
Bobty 3:1e06e89bc0c9 42 void begin(uint8_t *pDisplayBuf, uint16_t width, uint16_t height, uint16_t scrollWidth,
Bobty 3:1e06e89bc0c9 43 uint16_t numLines, int charSeparation = 1, int flashRate = 8);
yihui 0:13728deac7a7 44
yihui 0:13728deac7a7 45 /**
Bobty 2:cd2da920cf98 46 * draw a point - origin is like a graph with 0,0 at the lower-left corner
yihui 0:13728deac7a7 47 * @param x x
yihui 0:13728deac7a7 48 * @param y y
yihui 0:13728deac7a7 49 * @param pixel 0: led off, >0: led on
yihui 0:13728deac7a7 50 */
yihui 0:13728deac7a7 51 void drawPoint(uint16_t x, uint16_t y, uint8_t pixel);
yihui 0:13728deac7a7 52
yihui 0:13728deac7a7 53 /**
Bobty 2:cd2da920cf98 54 * draw a rect - origin is like a graph with 0,0 at the lower-left corner
yihui 0:13728deac7a7 55 * @param (x1, y1) top-left position
yihui 0:13728deac7a7 56 * @param (x2, y2) bottom-right position, not included in the rect
yihui 0:13728deac7a7 57 * @param pixel 0: rect off, >0: rect on
yihui 0:13728deac7a7 58 */
yihui 0:13728deac7a7 59 void drawRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t pixel);
yihui 0:13728deac7a7 60
yihui 0:13728deac7a7 61 /**
yihui 0:13728deac7a7 62 * draw a image
yihui 0:13728deac7a7 63 * @param (x1, y1) top-left position
yihui 0:13728deac7a7 64 * @param (x2, y2) bottom-right position, not included in the rect
yihui 0:13728deac7a7 65 * @param pixels contents, 1 bit to 1 led
yihui 0:13728deac7a7 66 */
yihui 0:13728deac7a7 67 void drawImage(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t *image);
yihui 0:13728deac7a7 68
yihui 0:13728deac7a7 69 /**
yihui 0:13728deac7a7 70 * turn off 1/16 leds and turn on another 1/16 leds
yihui 0:13728deac7a7 71 */
yihui 0:13728deac7a7 72 void scan();
yihui 0:13728deac7a7 73
Bobty 2:cd2da920cf98 74 void invertColour();
yihui 0:13728deac7a7 75
Bobty 2:cd2da920cf98 76 uint8_t isInvertedColour();
yihui 0:13728deac7a7 77
yihui 0:13728deac7a7 78 void on();
yihui 0:13728deac7a7 79
yihui 0:13728deac7a7 80 void off();
Bobty 1:79cf2e115449 81
Bobty 2:cd2da920cf98 82 // Passing lineIdx == -1 to the following functions resets all lines
Bobty 2:cd2da920cf98 83 // Lines are numbered starting at 0
Bobty 2:cd2da920cf98 84 void clear(int lineIdx = -1);
Bobty 2:cd2da920cf98 85 void scroll(int lineIdx, bool scrollLeft);
Bobty 2:cd2da920cf98 86 void scrollReset(int lineIdx = -1);
Bobty 2:cd2da920cf98 87 void scrollToPos(int lineIdx, int pos);
Bobty 2:cd2da920cf98 88 void setupScroll(int lineIdx, int scrollWidth, int scrollInc);
yihui 0:13728deac7a7 89
Bobty 2:cd2da920cf98 90 uint8_t reverseBits(uint8_t b);
Bobty 2:cd2da920cf98 91 int displayChar(int xPos, int yPos, char ch);
Bobty 2:cd2da920cf98 92 int displayLargeDigit(int curX, int curY, char ch);
Bobty 2:cd2da920cf98 93 int displayLine(int lineIdx, const char* line);
Bobty 3:1e06e89bc0c9 94
Bobty 3:1e06e89bc0c9 95 void setAlert(int lineIdx, bool alertOn);
Bobty 2:cd2da920cf98 96
Bobty 2:cd2da920cf98 97 // Called frequently and regularly to handle effects like scrolling
Bobty 2:cd2da920cf98 98 void serviceEffects();
Bobty 2:cd2da920cf98 99
yihui 0:13728deac7a7 100 private:
Bobty 2:cd2da920cf98 101 bool getRowsToWorkOn(int lineIdx, int &startRow, int &numRows);
yihui 0:13728deac7a7 102 DigitalOut a, b, c, d, oe, r1, stb, clk;
Bobty 2:cd2da920cf98 103 uint8_t *_pDisplayBuf;
yihui 0:13728deac7a7 104 uint16_t width;
yihui 0:13728deac7a7 105 uint16_t height;
Bobty 2:cd2da920cf98 106 uint16_t dispBufWidth;
Bobty 2:cd2da920cf98 107 uint16_t numLines;
yihui 0:13728deac7a7 108 uint8_t mask;
Bobty 2:cd2da920cf98 109 bool _isEnabled;
Bobty 2:cd2da920cf98 110 int _hScrollPos[LED_MATRIX_LEDS_VERTICALLY];
Bobty 2:cd2da920cf98 111 int _hScrollWidth[LED_MATRIX_LEDS_VERTICALLY];
Bobty 2:cd2da920cf98 112 bool _isBusy;
Bobty 2:cd2da920cf98 113 int _charSeparation;
Bobty 2:cd2da920cf98 114 int _lineScrollInc[LED_MATRIX_MAX_LINES];
Bobty 3:1e06e89bc0c9 115 bool _lineAlert[LED_MATRIX_MAX_LINES];
Bobty 3:1e06e89bc0c9 116 bool _lineInvert[LED_MATRIX_MAX_LINES];
Bobty 3:1e06e89bc0c9 117 int _flashCounter;
Bobty 3:1e06e89bc0c9 118 int _flashRate;
Bobty 3:1e06e89bc0c9 119 bool _flashState;
yihui 0:13728deac7a7 120 };
yihui 0:13728deac7a7 121
yihui 0:13728deac7a7 122 #endif