Akizuki 32x16 dot LED Matrix unit (K-03735) control library.
秋月電子の32×16ドットLEDマトリクス表示装置(K-03735)を制御するライブラリです。
バッファの内容をそのままLEDマトリクス装置に送ります。
LEDマトリクス表示装置は最大4台まで接続できるので、接続台数を必ず指定してください。(この台数でバッファのサイズを計算しています。)
行間表示は1msのdelayを入れています。パラメタで変更可能です。
このライブラリの呼び出し元は基本的にwhile()でループしてください。
初めてのライブラリなのでメンバ関数もドキュメントとかまだ最低限です。
おかしなところはぜひコメントをください。
表示例は以下ページをご覧ください。
Revision 1:2705be49d5e2, committed 2013-02-17
- Comitter:
- kanpapa
- Date:
- Sun Feb 17 14:38:20 2013 +0000
- Parent:
- 0:bf351a2fa565
- Child:
- 2:ddef08e13c8e
- Child:
- 10:9ce938cdeb33
- Commit message:
- beta1 release
Changed in this revision
akiledmatrix.cpp | Show annotated file Show diff for this revision Revisions of this file |
akiledmatrix.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/akiledmatrix.cpp Sun Feb 17 12:25:21 2013 +0000 +++ b/akiledmatrix.cpp Sun Feb 17 14:38:20 2013 +0000 @@ -6,13 +6,15 @@ PinName sin3, PinName clock, PinName latch, - PinName strobe) : + PinName strobe, + const unsigned int maxledunit) : _sin1(sin1), _sin2(sin2), _sin3(sin3), _clock(clock), _latch(latch), - _strobe(strobe) { + _strobe(strobe), + _maxledunit(maxledunit) { // initrize _sin1 = 0; _sin2 = 0; @@ -20,50 +22,49 @@ _clock = 0; _latch = 1; _strobe = 0; // LED ON + _maxledunit = 1; // The number of LED units. (default 1 unit) } -void AkiLedMatrix::display(const unsigned char *buffer, const int speed, const int maxled) { +void AkiLedMatrix::display(const unsigned char *buffer, const unsigned int delay) { int bufp = 0; // buffer pointer - while(1) { // loop - for (int y = 0; y < 16; y++){ - uint16_t led1_data = buffer[bufp + 0] * 256 + buffer[bufp + 1]; - uint16_t led2_data = buffer[bufp + 2] * 256 + buffer[bufp + 3]; + for (int y = 0; y < 16; y++){ + uint16_t led1_data = buffer[bufp + 0] * 256 + buffer[bufp + 1]; + uint16_t led2_data = buffer[bufp + 2] * 256 + buffer[bufp + 3]; - for (int x = 0; x < 16; x++){ - if (x == y) { - _sin1 = 1; - } else { - _sin1 = 0; - } + for (int x = 0; x < 16; x++){ + if (x == y){ + _sin1 = 1; + } else { + _sin1 = 0; + } - // LED1 - _sin2 = led1_data & 0x01; - led1_data = led1_data >> 1; + // LED1 + _sin2 = led1_data & 0x01; + led1_data = led1_data >> 1; - // LED2 - _sin3 = led2_data & 0x01; - led2_data = led2_data >> 1; + // LED2 + _sin3 = led2_data & 0x01; + led2_data = led2_data >> 1; - wait_us(2); // tSETUP min:1.2us + wait_us(2); // tSETUP min:1.2us - // set clock - _clock = 1; - wait_us(1); // twCLK min:1.0us - _clock = 0; - } + // set clock + _clock = 1; + wait_us(1); // twCLK min:1.0us + _clock = 0; + } - // set latch - _latch = 0; - wait_us(2); // twLAT min:2.0us - _latch = 1; + // set latch + _latch = 0; + wait_us(2); // twLAT min:2.0us + _latch = 1; - wait_ms(speed); + wait_us(delay); - bufp = bufp + 4; - if (bufp > (maxled * 16)) { - bufp = 0; - } + bufp = bufp + 4; + if (bufp > (_maxledunit * 16 * 16)) { + bufp = 0; } } }
--- a/akiledmatrix.h Sun Feb 17 12:25:21 2013 +0000 +++ b/akiledmatrix.h Sun Feb 17 14:38:20 2013 +0000 @@ -11,26 +11,79 @@ * #include "mbed.h" * #include "akiledmatrix.h" * - * AkiLedMatrix ledmatrix(p5, p6, p7, p8, p9, p10); + * // LEDMatrix mbed + * // ---------- -------- + * // 1 LED_PWR + * // 2 SIN_1 ----- p5 line + * // 3 SIN_2 ----- p6 LED1 row + * // 4 SIN_3 ----- p7 LED2 row + * // 5 CLOCK ----- p8 + * // 6 LATCH ----- p9 + * // 7 STROBE ---- p10 + * // 8 IC_PWR + * // 9 GND + * // 10 GND + * + * AkiLedMatrix ledmatrix(p5, p6, p7, p8, p9, p10, 1); * * int main() { - * ledmatrix.display(buf); + * const unsigned char buf[] = { + * 0xff,0xff,0xff,0xff, // D15 + * 0xff,0xff,0xff,0xff, // D14 + * 0xff,0xff,0xff,0xff, // D13 + * 0xff,0xe7,0xff,0xfc, // D12 + * 0xff,0xe7,0xff,0xfc, // D11 + * 0xff,0xe7,0xff,0xfc, // D10 + * 0x44,0x60,0xe0,0xe0, // D9 + * 0x00,0x20,0x40,0x40, // D8 + * 0x33,0x26,0x4e,0x4c, // D7 + * 0x33,0x26,0x40,0x4c, // D6 + * 0x33,0x26,0x4f,0xcc, // D5 + * 0x33,0x20,0x60,0xc0, // D4 + * 0x33,0x28,0xf1,0xe4, // D3 + * 0xff,0xff,0xff,0xff, // D2 + * 0xff,0xff,0xff,0xff, // D1 + * 0xff,0xff,0xff,0xff}; // D0 + * + * int delay = 1000; // dynamic time (us) + * + * while(1){ + * ledmatrix.display(buf, delay); + * } * } * @endcode */ class AkiLedMatrix { public: + /** Create AkiLedMatrix instance + * @param sin1 SIN_1 + * @param sin2 SIN_2 + * @param sin3 SIN_3 + * @param clock CLOCK IN + * @param latch LATCH IN + * @param strobe STROBE IN + * @param maxledunit The number of LED units. + */ AkiLedMatrix(PinName sin1, PinName sin2, PinName sin3, PinName clock, PinName latch, - PinName strobe); + PinName strobe, + const unsigned int maxledunit); - void display(const unsigned char *buffer, const int speed = 20, const int maxled = 4); + /** Displays the contents of the buffer + * + * @param buffer Display buffer + * @param delay Dynamic display delay in microseconds + * @returns + * void + */ + void display(const unsigned char *buffer, const unsigned int delay = 1000); private: DigitalOut _sin1,_sin2,_sin3,_clock,_latch,_strobe; + unsigned int _maxledunit; }; #endif \ No newline at end of file