Akizuki 32x16 dot LED Matrix unit (K-03735) control library.
秋月電子の32×16ドットLEDマトリクス表示装置(K-03735)を制御するライブラリです。
バッファの内容をそのままLEDマトリクス装置に送ります。
LEDマトリクス表示装置は最大4台まで接続できるので、接続台数を必ず指定してください。(この台数でバッファのサイズを計算しています。)
行間表示は1msのdelayを入れています。パラメタで変更可能です。
このライブラリの呼び出し元は基本的にwhile()でループしてください。
初めてのライブラリなのでメンバ関数もドキュメントとかまだ最低限です。
おかしなところはぜひコメントをください。
表示例は以下ページをご覧ください。
Revision 5:c055674c4a0b, committed 2013-06-09
- Comitter:
- kanpapa
- Date:
- Sun Jun 09 05:24:11 2013 +0000
- Parent:
- 4:920c540c6a61
- Child:
- 6:141717976896
- Commit message:
- add scroll function
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 Wed Jun 05 14:28:10 2013 +0000 +++ b/akiledmatrix.cpp Sun Jun 09 05:24:11 2013 +0000 @@ -1,5 +1,5 @@ +#include "mbed.h" #include "akiledmatrix.h" -#include "mbed.h" AkiLedMatrix::AkiLedMatrix(PinName sin1, PinName sin2, @@ -7,14 +7,18 @@ PinName clock, PinName latch, PinName strobe, - int ledunit) : + const int ledunit, + const int delay, + const int shift_count_init) : _sin1(sin1), _sin2(sin2), _sin3(sin3), _clock(clock), _latch(latch), _strobe(strobe), - _ledunit(ledunit) { + _ledunit(ledunit), + _delay(delay), + _shift_count_init(shift_count_init) { // initrize _sin1 = 0; _sin2 = 0; @@ -22,16 +26,51 @@ _clock = 0; _latch = 1; _strobe = 0; // LED ON + shift_count = shift_count_init; + } + +// +// bit shift array[buf_xsize] +// +void AkiLedMatrix::bitshift(unsigned char *array, int xsize){ + int top_bit = 0, work_bit = 0; + for (int y = 0; y < (16 * xsize); y = y + xsize){ + for (int x = 0; x < xsize; x++){ + if ((array[x + y] & 0x80) != 0){ + if (x == 0){ + top_bit = 1; + } else { + work_bit = 1; + } + } else { + if (x == 0){ + top_bit = 0; + } else { + work_bit = 0; + } + } + // Right shift + array[x + y] = array[x + y] << 1; + + if (x != 0){ + array[x + y - 1 ] = array[x + y - 1 ] | work_bit; + } + } + // set lower bit (last byte) + array[y + xsize - 1] = array[y + xsize - 1] | top_bit; + } } - -void AkiLedMatrix::display(const unsigned char *buffer, int delay) { + +void AkiLedMatrix::display(unsigned char *buffer) { + DigitalOut myled4(LED4); + int bufp = 0; // buffer pointer - for (int y = 0; y < 16; y++){ + for (int y = 0; y < 16; y++){ for (int ledno = (_ledunit - 1); ledno >= 0; ledno--){ uint16_t led1_data = buffer[ledno * 4 + bufp + 0] * 256 + buffer[ledno * 4 + bufp + 1]; uint16_t led2_data = buffer[ledno * 4 + bufp + 2] * 256 + buffer[ledno * 4 + bufp + 3]; - + for (int x = 0; x < 16; x++){ if (x == y){ _sin1 = 1; @@ -46,7 +85,7 @@ // LED2 _sin3 = led2_data & 0x01; led2_data = led2_data >> 1; - + wait_us(2); // tSETUP min:1.2us // set clock @@ -55,16 +94,31 @@ _clock = 0; } } + // set latch _latch = 0; wait_us(2); // twLAT min:2.0us _latch = 1; - wait_us(delay); + wait_us(_delay); bufp = bufp + (_ledunit * 4); - if (bufp > (_ledunit * 64)) { - bufp = 0; + + // shift check + if (shift_count-- == 0){ + bitshift(buffer, 8); + shift_count = _shift_count_init; + + // blink LED4 + if (myled4 == 1) { + myled4 = 0; + } else { + myled4 = 1; + } } } } + +int AkiLedMatrix::getLedunit(){ + return _ledunit; +}
--- a/akiledmatrix.h Wed Jun 05 14:28:10 2013 +0000 +++ b/akiledmatrix.h Sun Jun 09 05:24:11 2013 +0000 @@ -24,7 +24,11 @@ * // 9 GND * // 10 GND * - * AkiLedMatrix ledmatrix(p5, p6, p7, p8, p9, p10, 1); + * // ledunit = 8 + * // dynamic_delay = 1000 + * // scroll_delay = 50 + * + * AkiLedMatrix ledmatrix(p5, p6, p7, p8, p9, p10, 1, 1000, 50); * * int main() { * const unsigned char buf[] = { @@ -45,14 +49,13 @@ * 0xff,0xff,0xff,0xff, // D1 * 0xff,0xff,0xff,0xff}; // D0 * - * int delay = 1000; // dynamic time (us) - * * while(1){ - * ledmatrix.display(buf, delay); + * ledmatrix.display(buf); * } * } * @endcode */ + class AkiLedMatrix { public: /** Create AkiLedMatrix instance @@ -62,7 +65,9 @@ * @param clock CLOCK IN * @param latch LATCH IN * @param strobe STROBE IN - * @param ledunit The number of LED units. + * @param ledunit Number of LED units + * @param delay Dynamic display delay in microseconds + * @param shift_count_init scroll timing */ AkiLedMatrix(PinName sin1, PinName sin2, @@ -70,20 +75,43 @@ PinName clock, PinName latch, PinName strobe, - int ledunit); + const int ledunit, + const int delay, + const int shift_count_init); - /** 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, int delay = 1000); + /** Displays the contents of the buffer + * + * @param buffer Display buffer + * @returns + * void + */ + void display(unsigned char *buffer); + + /** Get LED unit number + * + * @param + * void + * @returns + * number of LED units + */ + int getLedunit(); private: + /** bit left shift + * + * @param + * unsigned char *array LED display buffer + * int xsize row char size + * @returns + * void + */ + void bitshift(unsigned char *array, int xsize); + DigitalOut _sin1,_sin2,_sin3,_clock,_latch,_strobe; - int _ledunit; + const int _ledunit; + const int _delay; + const int _shift_count_init; + int shift_count; }; -#endif \ No newline at end of file +#endif