Yihui Xiong / LEDMatrix

Dependents:   led_matrix

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LEDMatrix.h Source File

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 class LEDMatrix {
00028 public:
00029     LEDMatrix(PinName pinA, PinName pinB, PinName pinC, PinName pinD, PinName pinOE, PinName pinR1, PinName pinSTB, PinName pinCLK);
00030     
00031     /**
00032      * set the display's display buffer and number, the buffer's size must be not less than 512 * number / 8 bytes
00033      * @param displaybuf    display buffer
00034      * @param number        panels' number
00035      */
00036     void begin(uint8_t *displaybuf, uint16_t width, uint16_t height);
00037 
00038     /**
00039      * draw a point
00040      * @param x     x
00041      * @param y     y
00042      * @param pixel 0: led off, >0: led on
00043      */
00044     void drawPoint(uint16_t x, uint16_t y, uint8_t pixel);
00045 
00046     /**
00047      * draw a rect
00048      * @param (x1, y1)   top-left position
00049      * @param (x2, y2)   bottom-right position, not included in the rect
00050      * @param pixel      0: rect off, >0: rect on
00051      */
00052     void drawRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t pixel);
00053 
00054     /**
00055      * draw a image
00056      * @param (xoffset, yoffset)   top-left offset of image
00057      * @param (width, height)      image's width and height
00058      * @param pixels     contents, 1 bit to 1 led
00059      */
00060     void drawImage(uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height, const uint8_t *image);
00061 
00062     /**
00063      * Set screen buffer to zero
00064      */
00065     void clear();
00066 
00067     /**
00068      * turn off 1/16 leds and turn on another 1/16 leds
00069      */
00070     void scan();
00071 
00072     void reverse();
00073 
00074     uint8_t isReversed();
00075 
00076     void on();
00077 
00078     void off();
00079 
00080 private:
00081     DigitalOut a, b, c, d, oe, r1, stb, clk;
00082     uint8_t *displaybuf;
00083     uint16_t width;
00084     uint16_t height;
00085     uint8_t  mask;
00086     uint8_t  state;
00087 };
00088 
00089 #endif