Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of LEDMatrix by
LEDMatrix.h
00001 /** 00002 * LED Matrix library for http://www.seeedstudio.com/depot/ultrathin-16x32-red-led-matrix-panel-p-1582.html 00003 * The LED Matrix panel has 32x16 pixels. Several panel can be combined together as a large screen. 00004 * 00005 * Coordinate & Connection (mbed -> panel 0 -> panel 1 -> ...) 00006 * (0, 0) (0, 0) 00007 * +--------+--------+--------+ +--------+--------+ 00008 * | 5 | 3 | 1 | | 1 | 0 | 00009 * | | | | | | |<----- mbed 00010 * +--------+--------+--------+ +--------+--------+ 00011 * | 4 | 2 | 0 | (64, 16) 00012 * | | | |<----- mbed 00013 * +--------+--------+--------+ 00014 * (96, 32) 00015 * Copyright (c) 2013 Seeed Technology Inc. 00016 * @auther Yihui Xiong 00017 * @date Nov 7, 2013 00018 * @license Apache 00019 */ 00020 00021 00022 #ifndef __LED_MATRIX_H__ 00023 #define __LED_MATRIX_H__ 00024 00025 #include "mbed.h" 00026 00027 const int LED_MATRIX_LEDS_HORIZONTALLY = 32; 00028 const int LED_MATRIX_LEDS_VERTICALLY = 16; 00029 const int LED_MATRIX_MAX_LINES = 2; 00030 00031 class LEDMatrix 00032 { 00033 public: 00034 00035 LEDMatrix(PinName pinA, PinName pinB, PinName pinC, PinName pinD, PinName pinOE, PinName pinR1, PinName pinSTB, PinName pinCLK); 00036 00037 /** 00038 * set the display's display buffer and number, the buffer's size must be not less than 512 * number / 8 bytes 00039 * @param pDisplayBuf display buffer 00040 * @param number panels' number 00041 */ 00042 void begin(uint8_t *pDisplayBuf, uint16_t width, uint16_t height, uint16_t scrollWidth, 00043 uint16_t numLines, int charSeparation = 1, int flashRate = -1, int scrollRate = -1); 00044 00045 /** 00046 * draw a point - origin is like a graph with 0,0 at the lower-left corner 00047 * @param x x 00048 * @param y y 00049 * @param pixel 0: led off, >0: led on 00050 */ 00051 void drawPoint(uint16_t x, uint16_t y, uint8_t pixel); 00052 00053 /** 00054 * draw a rect - origin is like a graph with 0,0 at the lower-left corner 00055 * @param (x1, y1) top-left position 00056 * @param (x2, y2) bottom-right position, not included in the rect 00057 * @param pixel 0: rect off, >0: rect on 00058 */ 00059 void drawRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t pixel); 00060 00061 /** 00062 * draw a image 00063 * @param (x1, y1) top-left position 00064 * @param (x2, y2) bottom-right position, not included in the rect 00065 * @param pixels contents, 1 bit to 1 led 00066 */ 00067 void drawImage(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t *image); 00068 00069 /** 00070 * turn off 1/16 leds and turn on another 1/16 leds 00071 */ 00072 void scan(); 00073 00074 void invertColour(); 00075 00076 uint8_t isInvertedColour(); 00077 00078 void on(); 00079 00080 void off(); 00081 00082 // Passing lineIdx == -1 to the following functions resets all lines 00083 // Lines are numbered starting at 0 00084 void clear(int lineIdx = -1); 00085 void scroll(int lineIdx, bool scrollLeft); 00086 void scrollReset(int lineIdx = -1); 00087 void scrollToPos(int lineIdx, int pos); 00088 void setupScroll(int lineIdx, int scrollWidth, int scrollInc); 00089 00090 uint8_t reverseBits(uint8_t b); 00091 int displayChar(int xPos, int yPos, char ch); 00092 int displayLargeDigit(int curX, int curY, char ch); 00093 int displayLine(int lineIdx, const char* line); 00094 00095 void setScrollRate(int rate); 00096 void setFlashRate(int rate); 00097 void setHighlight(int lineIdx, bool highlightOn); 00098 00099 // Called frequently and regularly to handle effects like scrolling 00100 void serviceEffects(); 00101 00102 private: 00103 bool getRowsToWorkOn(int lineIdx, int &startRow, int &numRows); 00104 DigitalOut a, b, c, d, oe, r1, stb, clk; 00105 uint8_t *_pDisplayBuf; 00106 uint16_t width; 00107 uint16_t height; 00108 uint16_t dispBufWidth; 00109 uint16_t numLines; 00110 uint8_t mask; 00111 bool _isEnabled; 00112 int _hScrollPos[LED_MATRIX_LEDS_VERTICALLY]; 00113 int _hScrollWidth[LED_MATRIX_LEDS_VERTICALLY]; 00114 bool _isBusy; 00115 int _charSeparation; 00116 int _lineScrollInc[LED_MATRIX_MAX_LINES]; 00117 bool _lineHighlight[LED_MATRIX_MAX_LINES]; 00118 bool _lineInvert[LED_MATRIX_MAX_LINES]; 00119 int _flashCounter; 00120 int _flashRate; 00121 bool _flashState; 00122 int _scrollCounter; 00123 int _scrollRate; 00124 }; 00125 00126 #endif
Generated on Thu Jul 14 2022 22:43:16 by
1.7.2
