Hub08 LED matrix 64*16 soft scrolling
[Arduino] / Hub08_LedMatrix / LEDMatrix.h
1 /**
2  * LED Matrix library for http://www.seeedstudio.com/depot/ultrathin-16x32-red-led-matrix-panel-p-1582.html
3  * The LED Matrix panel has 32x16 pixels. Several panel can be combined together as a large screen.
4  *
5  * Coordinate & Connection (Arduino -> panel 0 -> panel 1 -> ...)
6  *   (0, 0)                                     (0, 0)
7  *     +--------+--------+--------+               +--------+--------+
8  *     |   5    |    4   |    3   |               |    1   |    0   |
9  *     |        |        |        |               |        |        |<----- Arduino
10  *     +--------+--------+--------+               +--------+--------+
11  *     |   2    |    1   |    0   |                              (64, 16)
12  *     |        |        |        |<----- Arduino
13  *     +--------+--------+--------+
14  *                             (96, 32)
15  *  Copyright (c) 2013 Seeed Technology Inc.
16  *  @auther     Yihui Xiong
17  *  @date       Nov 7, 2013
18  *  @license    MIT
19  */
20
21
22 #ifndef __LED_MATRIX_H__
23 #define __LED_MATRIX_H__
24
25  #include <stdint.h>
26
27 class LEDMatrix {
28 public:
29     LEDMatrix(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t oe, uint8_t r1, uint8_t stb, uint8_t clk);
30
31     /**
32      * set the display's display buffer and number, the buffer's size must be not less than 512 * number / 8 bytes
33      * @param displaybuf    display buffer
34      * @param number        panels' number
35      */
36     void begin(uint8_t *displaybuf, uint16_t width, uint16_t height);
37
38     /**
39      * draw a point
40      * @param x     x
41      * @param y     y
42      * @param pixel 0: led off, >0: led on
43      */
44     void drawPoint(uint16_t x, uint16_t y, uint8_t pixel);
45
46     /**
47      * draw a rect
48      * @param (x1, y1)   top-left position
49      * @param (x2, y2)   bottom-right position, not included in the rect
50      * @param pixel      0: rect off, >0: rect on
51      */
52     void drawRect(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t pixel);
53
54     /**
55      * draw a image
56      * @param (xoffset, yoffset)   top-left offset of image
57      * @param (width, height)      image's width and height
58      * @param pixels     contents, 1 bit to 1 led
59      */
60     void drawImage(uint16_t xoffset, uint16_t yoffset, uint16_t width, uint16_t height, const uint8_t *image);
61
62     /**
63      * Set screen buffer to zero
64      */
65     void clear();
66
67     /**
68      * turn off 1/16 leds and turn on another 1/16 leds
69      */
70     void scan();
71
72     void reverse();
73
74     uint8_t isReversed();
75
76     void on();
77
78     void off();
79
80 private:
81     uint8_t clk, r1, stb, oe, a, b, c, d;
82     uint8_t *displaybuf;
83     uint16_t width;
84     uint16_t height;
85     uint8_t  mask;
86     uint8_t  state;
87 };
88
89 #endif