Ghz2000's 14Segment LED Display Library
Dependents: Nucleo_Seg14Display
Ghz2000製 14セグ表示器
http://ghz2000.dip.jp/wordpress/?p=665
mbed用のサンプルプログラムです。 ライブラリ化してあるので、インポートして使用することが出来ます。
注意事項
一度に読み込めるテキストは30文字です。 それを超えると変な文字が表示されます。
今後
スクロールが終わった時のコールバックを作って、30文字以上の文字列も流せるようにしたいです。 スイッチサイエンスほかで販売予定。
lib14Seg.cpp@2:eb91996f0a20, 2016-07-06 (annotated)
- Committer:
- ghz2000
- Date:
- Wed Jul 06 05:59:18 2016 +0000
- Revision:
- 2:eb91996f0a20
- Parent:
- 0:e64e0d7aad81
Fix Comment and Class Document
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ghz2000 | 0:e64e0d7aad81 | 1 | #include "lib14Seg.hpp" |
ghz2000 | 0:e64e0d7aad81 | 2 | #include "mbed.h" |
ghz2000 | 0:e64e0d7aad81 | 3 | |
ghz2000 | 0:e64e0d7aad81 | 4 | C14Segment::C14Segment(){ |
ghz2000 | 0:e64e0d7aad81 | 5 | // bitSet(TIMSK2, TOIE2); |
ghz2000 | 0:e64e0d7aad81 | 6 | |
ghz2000 | 0:e64e0d7aad81 | 7 | // SPI.begin(); |
ghz2000 | 0:e64e0d7aad81 | 8 | // SPI.setBitOrder(MSBFIRST); |
ghz2000 | 0:e64e0d7aad81 | 9 | // SPI.setClockDivider(SPI_CLOCK_DIV64); |
ghz2000 | 0:e64e0d7aad81 | 10 | // SPI.setDataMode(SPI_MODE0); |
ghz2000 | 0:e64e0d7aad81 | 11 | |
ghz2000 | 0:e64e0d7aad81 | 12 | m_speed = 0; |
ghz2000 | 0:e64e0d7aad81 | 13 | } |
ghz2000 | 0:e64e0d7aad81 | 14 | |
ghz2000 | 0:e64e0d7aad81 | 15 | C14Segment LED14Seg; |
ghz2000 | 0:e64e0d7aad81 | 16 | Ticker ticker; |
ghz2000 | 0:e64e0d7aad81 | 17 | |
ghz2000 | 0:e64e0d7aad81 | 18 | void C14Segment::init(PinName MOSI,PinName MISO, PinName SCK, PinName RCK, int kido, int ViewLength){ |
ghz2000 | 0:e64e0d7aad81 | 19 | setSPI(MOSI, MISO, SCK, RCK); |
ghz2000 | 0:e64e0d7aad81 | 20 | setBlight(kido); |
ghz2000 | 0:e64e0d7aad81 | 21 | setViewLength(ViewLength); |
ghz2000 | 0:e64e0d7aad81 | 22 | |
ghz2000 | 0:e64e0d7aad81 | 23 | //タイマー割り込みを設定 |
ghz2000 | 0:e64e0d7aad81 | 24 | ticker.attach_us( &LED14Seg, &C14Segment::update, 1000); |
ghz2000 | 0:e64e0d7aad81 | 25 | } |
ghz2000 | 0:e64e0d7aad81 | 26 | |
ghz2000 | 0:e64e0d7aad81 | 27 | void C14Segment::setSPI(PinName MOSI, PinName MISO, PinName SCK, PinName RCK){ |
ghz2000 | 0:e64e0d7aad81 | 28 | m_MOSI = MOSI; |
ghz2000 | 0:e64e0d7aad81 | 29 | m_MISO = MISO; |
ghz2000 | 0:e64e0d7aad81 | 30 | m_SCK = SCK; |
ghz2000 | 0:e64e0d7aad81 | 31 | m_RCK = RCK; |
ghz2000 | 0:e64e0d7aad81 | 32 | |
ghz2000 | 0:e64e0d7aad81 | 33 | mp_SPIdevice = new SPI(m_MOSI, m_MISO, m_SCK); |
ghz2000 | 0:e64e0d7aad81 | 34 | mp_DigitalOutRCK = new DigitalOut(m_RCK); |
ghz2000 | 0:e64e0d7aad81 | 35 | } |
ghz2000 | 0:e64e0d7aad81 | 36 | |
ghz2000 | 0:e64e0d7aad81 | 37 | void C14Segment::setBlight(int kido){ |
ghz2000 | 0:e64e0d7aad81 | 38 | m_kido = kido; |
ghz2000 | 0:e64e0d7aad81 | 39 | } |
ghz2000 | 0:e64e0d7aad81 | 40 | |
ghz2000 | 0:e64e0d7aad81 | 41 | void C14Segment::setScrollSpeed(int scrollSpeed){ |
ghz2000 | 0:e64e0d7aad81 | 42 | m_speed = scrollSpeed; |
ghz2000 | 0:e64e0d7aad81 | 43 | } |
ghz2000 | 0:e64e0d7aad81 | 44 | |
ghz2000 | 0:e64e0d7aad81 | 45 | void C14Segment::setViewLength(int ViewLength){ |
ghz2000 | 0:e64e0d7aad81 | 46 | m_ViewLength = ViewLength-1; |
ghz2000 | 0:e64e0d7aad81 | 47 | } |
ghz2000 | 0:e64e0d7aad81 | 48 | |
ghz2000 | 0:e64e0d7aad81 | 49 | void C14Segment::setChar(char *input){ |
ghz2000 | 0:e64e0d7aad81 | 50 | int i=0; |
ghz2000 | 0:e64e0d7aad81 | 51 | memset(m_str, 0, __LEN * 2); |
ghz2000 | 0:e64e0d7aad81 | 52 | for(; i<__LEN -1 && input[i]!=NULL; i++){ |
ghz2000 | 0:e64e0d7aad81 | 53 | m_str[i] = ascii[ input[i] - ' '+1]; //変な文字が来た時対策をしてない |
ghz2000 | 0:e64e0d7aad81 | 54 | } |
ghz2000 | 0:e64e0d7aad81 | 55 | m_str[i] = 0x8000; |
ghz2000 | 0:e64e0d7aad81 | 56 | } |
ghz2000 | 0:e64e0d7aad81 | 57 | |
ghz2000 | 0:e64e0d7aad81 | 58 | void C14Segment::showStop(){ |
ghz2000 | 0:e64e0d7aad81 | 59 | for(int i=0; i<m_ViewLength +1; i++){ |
ghz2000 | 0:e64e0d7aad81 | 60 | m_view[m_ViewLength - i] = m_str[i]; //文字が少ない時にバグるんじゃないかな |
ghz2000 | 0:e64e0d7aad81 | 61 | } |
ghz2000 | 0:e64e0d7aad81 | 62 | m_speed = 0; |
ghz2000 | 0:e64e0d7aad81 | 63 | } |
ghz2000 | 0:e64e0d7aad81 | 64 | |
ghz2000 | 0:e64e0d7aad81 | 65 | void C14Segment::scroll(){ |
ghz2000 | 0:e64e0d7aad81 | 66 | static int scroll; |
ghz2000 | 0:e64e0d7aad81 | 67 | for(int i=0; i<m_ViewLength +1; i++){ |
ghz2000 | 0:e64e0d7aad81 | 68 | |
ghz2000 | 0:e64e0d7aad81 | 69 | //スクロールするときは桁数分ずらして空白からスタートする。 |
ghz2000 | 0:e64e0d7aad81 | 70 | if(i + scroll < m_ViewLength){ |
ghz2000 | 0:e64e0d7aad81 | 71 | //空白を入れる |
ghz2000 | 0:e64e0d7aad81 | 72 | m_view[m_ViewLength - i] = 0x00; |
ghz2000 | 0:e64e0d7aad81 | 73 | }else{ |
ghz2000 | 0:e64e0d7aad81 | 74 | //文字をスクロール用にセットする |
ghz2000 | 0:e64e0d7aad81 | 75 | m_view[m_ViewLength - i] = m_str[i+scroll-m_ViewLength]; //文字が少ない時にバグるんじゃないかな |
ghz2000 | 0:e64e0d7aad81 | 76 | |
ghz2000 | 0:e64e0d7aad81 | 77 | //全部通り過ぎたところと 0x8000(表示用終端文字)を比較して一致したらスクロールをリセット |
ghz2000 | 0:e64e0d7aad81 | 78 | // if(m_str[i+scroll-m_ViewLength-m_ViewLength] == 0x8000) scroll=-m_ViewLength-1; |
ghz2000 | 0:e64e0d7aad81 | 79 | if(m_str[i+scroll-m_ViewLength-m_ViewLength] == 0x8000) scroll=-m_ViewLength; |
ghz2000 | 0:e64e0d7aad81 | 80 | } |
ghz2000 | 0:e64e0d7aad81 | 81 | } |
ghz2000 | 0:e64e0d7aad81 | 82 | scroll++; |
ghz2000 | 0:e64e0d7aad81 | 83 | } |
ghz2000 | 0:e64e0d7aad81 | 84 | |
ghz2000 | 0:e64e0d7aad81 | 85 | void C14Segment::putnum(){ |
ghz2000 | 0:e64e0d7aad81 | 86 | } |
ghz2000 | 0:e64e0d7aad81 | 87 | |
ghz2000 | 0:e64e0d7aad81 | 88 | void C14Segment::cls(){ |
ghz2000 | 0:e64e0d7aad81 | 89 | } |
ghz2000 | 0:e64e0d7aad81 | 90 | |
ghz2000 | 0:e64e0d7aad81 | 91 | uint16_t cycleX[8] = {0x1000, 0x2000, 0x0400, 0x0002, 0x0004, 0x0008, 0x0010, 0x0800 }; |
ghz2000 | 0:e64e0d7aad81 | 92 | uint16_t cycleO[6] = {0x0200, 0x4000, 0x0001, 0x0020, 0x0080, 0x0100 }; |
ghz2000 | 0:e64e0d7aad81 | 93 | |
ghz2000 | 0:e64e0d7aad81 | 94 | //割り込みルーチン |
ghz2000 | 0:e64e0d7aad81 | 95 | void C14Segment::update(){ |
ghz2000 | 0:e64e0d7aad81 | 96 | static uint8_t row; |
ghz2000 | 0:e64e0d7aad81 | 97 | static int count; |
ghz2000 | 0:e64e0d7aad81 | 98 | |
ghz2000 | 0:e64e0d7aad81 | 99 | |
ghz2000 | 0:e64e0d7aad81 | 100 | *mp_DigitalOutRCK = 0; |
ghz2000 | 0:e64e0d7aad81 | 101 | |
ghz2000 | 0:e64e0d7aad81 | 102 | |
ghz2000 | 0:e64e0d7aad81 | 103 | // SPI.transfer(m_kido << 4 | (0x0F & ~(1<<row)) ); |
ghz2000 | 0:e64e0d7aad81 | 104 | mp_SPIdevice->write((0xFF & ~(1<<row)) ); |
ghz2000 | 0:e64e0d7aad81 | 105 | mp_SPIdevice->write(m_view[row] >> 8 & 0xFF ); |
ghz2000 | 0:e64e0d7aad81 | 106 | mp_SPIdevice->write(m_view[row] & 0xFF ); |
ghz2000 | 0:e64e0d7aad81 | 107 | |
ghz2000 | 0:e64e0d7aad81 | 108 | *mp_DigitalOutRCK = 1; |
ghz2000 | 0:e64e0d7aad81 | 109 | |
ghz2000 | 0:e64e0d7aad81 | 110 | if(m_speed){ |
ghz2000 | 0:e64e0d7aad81 | 111 | if(m_speed < count){ |
ghz2000 | 0:e64e0d7aad81 | 112 | scroll(); |
ghz2000 | 0:e64e0d7aad81 | 113 | count = 0; |
ghz2000 | 0:e64e0d7aad81 | 114 | } |
ghz2000 | 0:e64e0d7aad81 | 115 | count++; |
ghz2000 | 0:e64e0d7aad81 | 116 | } |
ghz2000 | 0:e64e0d7aad81 | 117 | |
ghz2000 | 0:e64e0d7aad81 | 118 | row++; |
ghz2000 | 0:e64e0d7aad81 | 119 | // row &=0x03; //4桁 |
ghz2000 | 0:e64e0d7aad81 | 120 | row &=0x07; //8桁 |
ghz2000 | 0:e64e0d7aad81 | 121 | } |
ghz2000 | 0:e64e0d7aad81 | 122 | |
ghz2000 | 0:e64e0d7aad81 | 123 | const uint16_t C14Segment::ascii[] = { sign_, |
ghz2000 | 0:e64e0d7aad81 | 124 | sign_, sign_Exclamation, sign_Wquot, sign_Sharp, sign_Doll, sign_Percent, sign_And, sign_Quot, sign_RoundBracketS, sign_RoundBracketE, sign_Asta, sign_Plus, sign_Comma, sign_Minus, sign_dot, sign_Slash, |
ghz2000 | 0:e64e0d7aad81 | 125 | sign_0, sign_1, sign_2, sign_3, sign_4, sign_5, sign_6, sign_7, sign_8, sign_9, sign_Colon , sign_SemiColon , sign_AngleS , sign_Equal , sign_AngleE , sign_Question , |
ghz2000 | 0:e64e0d7aad81 | 126 | sign_At, sign_A, sign_B, sign_C, sign_D, sign_E, sign_F, sign_G, sign_H, sign_I, sign_J, sign_K, sign_L, sign_M, sign_N, sign_O, |
ghz2000 | 0:e64e0d7aad81 | 127 | sign_P, sign_Q, sign_R, sign_S, sign_T, sign_U, sign_V, sign_W, sign_X, sign_Y, sign_Z, sign_BoxS , sign_En , sign_BoxE , sign_Hat , sign_Underbar , |
ghz2000 | 0:e64e0d7aad81 | 128 | sign_Grave, sign_a, sign_b, sign_c, sign_d, sign_e, sign_f, sign_g, sign_h, sign_i, sign_j, sign_k, sign_l, sign_m, sign_n, sign_o, |
ghz2000 | 0:e64e0d7aad81 | 129 | sign_p, sign_q, sign_r, sign_s, sign_t, sign_u, sign_v, sign_w, sign_x, sign_y, sign_z, sign_CurlyBracketS, sign_Tate, sign_CurlyBracketE, sign_Child}; |
ghz2000 | 0:e64e0d7aad81 | 130 |