このライブラリは8*8dotmatrixLedの輝度を階調制御します。 8*8dotmatrixLed以外でも8個のLEDを1組にしたものを1組から8組まで制御できます。 LEDの階調制御は、ON,OFFの指示で輝度を0から100%まで1秒かけて変化させることができます。 それ以外にも、輝度を直接指示することもできます。 This library is the brightness of the tone controls 8 * 8dotmatrixLed. You can control up to eight pairs of those in one set of eight pairs in the LED than 8 * 8dotmatrixLed. Tone control of the LED, ON, can be varied over a second from 0 to 100% brightness at the direction of OFF. Besides this, the intensity can be directly ordered.
Dependents: eightDotMatrixLedLibraryExample test10_rev2
EightDotMatrixLed.h@0:3df409a1aa42, 2011-12-03 (annotated)
- Committer:
- suupen
- Date:
- Sat Dec 03 23:01:36 2011 +0000
- Revision:
- 0:3df409a1aa42
V1.01 12/04 example program comment fix.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suupen | 0:3df409a1aa42 | 1 | /* mbed Eight Dot Matrix LED Library |
suupen | 0:3df409a1aa42 | 2 | * Copyright (c) 2011 suupen |
suupen | 0:3df409a1aa42 | 3 | * |
suupen | 0:3df409a1aa42 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
suupen | 0:3df409a1aa42 | 5 | * of this software and associated documentation files (the "Software"), to deal |
suupen | 0:3df409a1aa42 | 6 | * in the Software without restriction, including without limitation the rights |
suupen | 0:3df409a1aa42 | 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
suupen | 0:3df409a1aa42 | 8 | * copies of the Software, and to permit persons to whom the Software is |
suupen | 0:3df409a1aa42 | 9 | * furnished to do so, subject to the following conditions: |
suupen | 0:3df409a1aa42 | 10 | * |
suupen | 0:3df409a1aa42 | 11 | * The above copyright notice and this permission notice shall be included in |
suupen | 0:3df409a1aa42 | 12 | * all copies or substantial portions of the Software. |
suupen | 0:3df409a1aa42 | 13 | * |
suupen | 0:3df409a1aa42 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
suupen | 0:3df409a1aa42 | 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
suupen | 0:3df409a1aa42 | 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
suupen | 0:3df409a1aa42 | 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
suupen | 0:3df409a1aa42 | 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
suupen | 0:3df409a1aa42 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
suupen | 0:3df409a1aa42 | 20 | * THE SOFTWARE. |
suupen | 0:3df409a1aa42 | 21 | */ |
suupen | 0:3df409a1aa42 | 22 | |
suupen | 0:3df409a1aa42 | 23 | |
suupen | 0:3df409a1aa42 | 24 | //================================ |
suupen | 0:3df409a1aa42 | 25 | // EightDotMatrixLed.h |
suupen | 0:3df409a1aa42 | 26 | // V1.0 : 2011/12/03 |
suupen | 0:3df409a1aa42 | 27 | // |
suupen | 0:3df409a1aa42 | 28 | //================================ |
suupen | 0:3df409a1aa42 | 29 | #ifndef _EIGHTDOTMATRIXLED_H |
suupen | 0:3df409a1aa42 | 30 | #define _EIGHTDOTMATRIXLED_H |
suupen | 0:3df409a1aa42 | 31 | |
suupen | 0:3df409a1aa42 | 32 | /** Seven segment Numeric LED control class |
suupen | 0:3df409a1aa42 | 33 | * |
suupen | 0:3df409a1aa42 | 34 | * Example: |
suupen | 0:3df409a1aa42 | 35 | * @code |
suupen | 0:3df409a1aa42 | 36 | * //============================================ |
suupen | 0:3df409a1aa42 | 37 | * // eightDotMatrixLed Library Example |
suupen | 0:3df409a1aa42 | 38 | * // |
suupen | 0:3df409a1aa42 | 39 | * // This program is used to control the LED 32. |
suupen | 0:3df409a1aa42 | 40 | * // |
suupen | 0:3df409a1aa42 | 41 | * // |
suupen | 0:3df409a1aa42 | 42 | * // <schematic> |
suupen | 0:3df409a1aa42 | 43 | * // --|>|-- |
suupen | 0:3df409a1aa42 | 44 | * // A K |
suupen | 0:3df409a1aa42 | 45 | * // seg A(p5) -----R(200[ohm])--- LED ----- com0(p13) |
suupen | 0:3df409a1aa42 | 46 | * // | |
suupen | 0:3df409a1aa42 | 47 | * // -- R(200[ohm])--- LED ----- com1(p14) |
suupen | 0:3df409a1aa42 | 48 | * // | |
suupen | 0:3df409a1aa42 | 49 | * // -- R(200[ohm])--- LED ----- com2(p28) |
suupen | 0:3df409a1aa42 | 50 | * // | |
suupen | 0:3df409a1aa42 | 51 | * // -- R(200[ohm])--- LED ----- com3(p27) |
suupen | 0:3df409a1aa42 | 52 | * // |
suupen | 0:3df409a1aa42 | 53 | * // |
suupen | 0:3df409a1aa42 | 54 | * // same : segB(p6), segC(p7), segD(p8), segE(p9), segF(p10), segG(p11), segH(p12) |
suupen | 0:3df409a1aa42 | 55 | * // |
suupen | 0:3df409a1aa42 | 56 | * // <Description of LED control> |
suupen | 0:3df409a1aa42 | 57 | * // com0 Led off to on ,on to off smooth (lighting = 0 to 100 [%] |
suupen | 0:3df409a1aa42 | 58 | * // com1 Led off to on smooth, on to off hard |
suupen | 0:3df409a1aa42 | 59 | * // com2 Led off to on, on to off smooth (lighting = 0 to gray data) |
suupen | 0:3df409a1aa42 | 60 | * // com3 gray data movement |
suupen | 0:3df409a1aa42 | 61 | * // |
suupen | 0:3df409a1aa42 | 62 | * //============================================= |
suupen | 0:3df409a1aa42 | 63 | * |
suupen | 0:3df409a1aa42 | 64 | * #include "mbed.h" |
suupen | 0:3df409a1aa42 | 65 | * |
suupen | 0:3df409a1aa42 | 66 | * #include "EightDotMatrixLed.h" |
suupen | 0:3df409a1aa42 | 67 | * |
suupen | 0:3df409a1aa42 | 68 | * // common type (0:anode common 1:cathode common) |
suupen | 0:3df409a1aa42 | 69 | * // | |
suupen | 0:3df409a1aa42 | 70 | * // | segA segB segC segD segE segF segG segh com1 com2 com3 com4 (com5 to com8 = disable) |
suupen | 0:3df409a1aa42 | 71 | * // | | | | | | | | | | | | | |
suupen | 0:3df409a1aa42 | 72 | * EightDotMatrixLed segmentled(1, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p28, p27); |
suupen | 0:3df409a1aa42 | 73 | * |
suupen | 0:3df409a1aa42 | 74 | * // com0 Led off to on ,on to off smooth (lighting = 0 to 100 [%] |
suupen | 0:3df409a1aa42 | 75 | * // com1 Led off to on smooth, on to off hard |
suupen | 0:3df409a1aa42 | 76 | * // com2 Led off to on, on to off smooth (lighting = 0 to gray data) |
suupen | 0:3df409a1aa42 | 77 | * // com3 gray data movement |
suupen | 0:3df409a1aa42 | 78 | * |
suupen | 0:3df409a1aa42 | 79 | * uint8_t D_dotGrayData[4][8] = { |
suupen | 0:3df409a1aa42 | 80 | * {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // com0 disable |
suupen | 0:3df409a1aa42 | 81 | * {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // com1 disable |
suupen | 0:3df409a1aa42 | 82 | * {0, 14, 29, 43, 57, 71, 86, 100}, // com2 enable (0 to 100 [%]) |
suupen | 0:3df409a1aa42 | 83 | * {0, 14, 29, 43, 57, 71, 86, 100}, // com3 enable (0 to 100 [%]) |
suupen | 0:3df409a1aa42 | 84 | * }; |
suupen | 0:3df409a1aa42 | 85 | * uint8_t D_dotDigitalData[4][8] = { |
suupen | 0:3df409a1aa42 | 86 | * {0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // com0 0:off, 1:on |
suupen | 0:3df409a1aa42 | 87 | * {0x01, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // com1 0:disalbe 1:on |
suupen | 0:3df409a1aa42 | 88 | * {0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, // com2 0:off, 1:on |
suupen | 0:3df409a1aa42 | 89 | * {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} // com3 disable |
suupen | 0:3df409a1aa42 | 90 | * }; |
suupen | 0:3df409a1aa42 | 91 | * |
suupen | 0:3df409a1aa42 | 92 | * Timer timer; // data change timer |
suupen | 0:3df409a1aa42 | 93 | * |
suupen | 0:3df409a1aa42 | 94 | * int main() { |
suupen | 0:3df409a1aa42 | 95 | * uint8_t com, seg; |
suupen | 0:3df409a1aa42 | 96 | * uint8_t wk0, wk1, wk2, wk3; |
suupen | 0:3df409a1aa42 | 97 | * |
suupen | 0:3df409a1aa42 | 98 | * timer.start(); |
suupen | 0:3df409a1aa42 | 99 | * |
suupen | 0:3df409a1aa42 | 100 | * while(1) { |
suupen | 0:3df409a1aa42 | 101 | * // After 500[ms] to start the process |
suupen | 0:3df409a1aa42 | 102 | * if(timer.read_ms() >= 500){ |
suupen | 0:3df409a1aa42 | 103 | * timer.reset(); |
suupen | 0:3df409a1aa42 | 104 | * |
suupen | 0:3df409a1aa42 | 105 | * // com0 Led off to on ,on to off smooth (lighting = 0 to 100 [%] |
suupen | 0:3df409a1aa42 | 106 | * wk0 = D_dotDigitalData[0][7]; |
suupen | 0:3df409a1aa42 | 107 | * for(seg = 7; seg > 0; seg--){ |
suupen | 0:3df409a1aa42 | 108 | * D_dotDigitalData[0][seg] = D_dotDigitalData[0][seg - 1]; |
suupen | 0:3df409a1aa42 | 109 | * } |
suupen | 0:3df409a1aa42 | 110 | * D_dotDigitalData[0][0] = wk0; |
suupen | 0:3df409a1aa42 | 111 | * |
suupen | 0:3df409a1aa42 | 112 | * // com1 Led off to on smooth, on to off hard |
suupen | 0:3df409a1aa42 | 113 | * wk1 = D_dotDigitalData[1][7]; |
suupen | 0:3df409a1aa42 | 114 | * for(seg = 7; seg > 0; seg--){ |
suupen | 0:3df409a1aa42 | 115 | * D_dotDigitalData[1][seg] = D_dotDigitalData[1][seg - 1]; |
suupen | 0:3df409a1aa42 | 116 | * } |
suupen | 0:3df409a1aa42 | 117 | * D_dotDigitalData[1][0] = wk1; |
suupen | 0:3df409a1aa42 | 118 | * |
suupen | 0:3df409a1aa42 | 119 | * // com2 Led off to on, on to off smooth (lighting = 0 to gray data) |
suupen | 0:3df409a1aa42 | 120 | * wk2 = D_dotDigitalData[2][7]; |
suupen | 0:3df409a1aa42 | 121 | * for(seg = 7; seg > 0; seg--){ |
suupen | 0:3df409a1aa42 | 122 | * D_dotDigitalData[2][seg] = D_dotDigitalData[2][seg - 1]; |
suupen | 0:3df409a1aa42 | 123 | * } |
suupen | 0:3df409a1aa42 | 124 | * D_dotDigitalData[2][0] = wk2; |
suupen | 0:3df409a1aa42 | 125 | * |
suupen | 0:3df409a1aa42 | 126 | * // com3 gray data movement |
suupen | 0:3df409a1aa42 | 127 | * wk3 = D_dotGrayData[3][7]; |
suupen | 0:3df409a1aa42 | 128 | * for(seg = 7; seg > 0; seg--){ |
suupen | 0:3df409a1aa42 | 129 | * D_dotGrayData[3][seg] = D_dotGrayData[3][seg - 1]; |
suupen | 0:3df409a1aa42 | 130 | * } |
suupen | 0:3df409a1aa42 | 131 | * D_dotGrayData[3][0] = wk3; |
suupen | 0:3df409a1aa42 | 132 | * } |
suupen | 0:3df409a1aa42 | 133 | * |
suupen | 0:3df409a1aa42 | 134 | * // This function, please repeat the process in less than 1ms. |
suupen | 0:3df409a1aa42 | 135 | * segmentled.EightDotMatrixLed_main((uint8_t*)D_dotGrayData, (uint8_t*)D_dotDigitalData); |
suupen | 0:3df409a1aa42 | 136 | * |
suupen | 0:3df409a1aa42 | 137 | * } |
suupen | 0:3df409a1aa42 | 138 | *} |
suupen | 0:3df409a1aa42 | 139 | * @endcode |
suupen | 0:3df409a1aa42 | 140 | */ |
suupen | 0:3df409a1aa42 | 141 | |
suupen | 0:3df409a1aa42 | 142 | |
suupen | 0:3df409a1aa42 | 143 | |
suupen | 0:3df409a1aa42 | 144 | #include "types.h" |
suupen | 0:3df409a1aa42 | 145 | |
suupen | 0:3df409a1aa42 | 146 | class EightDotMatrixLed { |
suupen | 0:3df409a1aa42 | 147 | public: |
suupen | 0:3df409a1aa42 | 148 | |
suupen | 0:3df409a1aa42 | 149 | |
suupen | 0:3df409a1aa42 | 150 | |
suupen | 0:3df409a1aa42 | 151 | /** Create a eight dot matrix led array object connected to the specified DigitalOut pin |
suupen | 0:3df409a1aa42 | 152 | * @param commonPole The polarity of the seven segment led common 0:Anode common, 1:Cathode common |
suupen | 0:3df409a1aa42 | 153 | * @param seg_a - seg_h DigitalOut pin to connect to. To provide members with an array of uint8_t digit minutes. |
suupen | 0:3df409a1aa42 | 154 | * @param com_1 - com_8 DigitalOut pin to connect to. To provide members with an array of uint8_t digit minutes. 8 digits maximum |
suupen | 0:3df409a1aa42 | 155 | */ |
suupen | 0:3df409a1aa42 | 156 | EightDotMatrixLed(uint8_t commonPole, |
suupen | 0:3df409a1aa42 | 157 | PinName seg_a, PinName seg_b, PinName seg_c, PinName seg_d, PinName seg_e, PinName seg_f, PinName seg_g, PinName seg_h, |
suupen | 0:3df409a1aa42 | 158 | PinName com_1 = NC, PinName com_2 = NC, PinName com_3 = NC, PinName com_4 = NC, |
suupen | 0:3df409a1aa42 | 159 | PinName com_5 = NC, PinName com_6 = NC, PinName com_7 = NC, PinName com_8 = NC); |
suupen | 0:3df409a1aa42 | 160 | |
suupen | 0:3df409a1aa42 | 161 | /** Data set to the seven segment LED display |
suupen | 0:3df409a1aa42 | 162 | * @param uint8_t* grayData[8][8] address pointer : 0 - 100 (1/1 [%]/count) other:disable example 0:ledOff, 100:led max lighting |
suupen | 0:3df409a1aa42 | 163 | * @param uint8_t* digitalData[8][8] address pointer : 0 :ledOff 1 : ledOn other:disable (1[s] de henka) |
suupen | 0:3df409a1aa42 | 164 | */ |
suupen | 0:3df409a1aa42 | 165 | void EightDotMatrixLed_main(uint8_t* grayData, uint8_t* digitalData); |
suupen | 0:3df409a1aa42 | 166 | |
suupen | 0:3df409a1aa42 | 167 | private: |
suupen | 0:3df409a1aa42 | 168 | void segmentGrayDataKosin(void); |
suupen | 0:3df409a1aa42 | 169 | void comAllClear(void); |
suupen | 0:3df409a1aa42 | 170 | void segAllClear(void); |
suupen | 0:3df409a1aa42 | 171 | void segDataSet(uint8_t keta); |
suupen | 0:3df409a1aa42 | 172 | void output(void); |
suupen | 0:3df409a1aa42 | 173 | |
suupen | 0:3df409a1aa42 | 174 | // pin set_seg, _com; |
suupen | 0:3df409a1aa42 | 175 | DigitalOut _seg_a, _seg_b, _seg_c, _seg_d, _seg_e, _seg_f, _seg_g, _seg_h; |
suupen | 0:3df409a1aa42 | 176 | DigitalOut _com_1, _com_2, _com_3, _com_4, _com_5, _com_6, _com_7, _com_8; |
suupen | 0:3df409a1aa42 | 177 | |
suupen | 0:3df409a1aa42 | 178 | Ticker timer; |
suupen | 0:3df409a1aa42 | 179 | |
suupen | 0:3df409a1aa42 | 180 | #define Z_comSuu (8) // max number of common pin |
suupen | 0:3df409a1aa42 | 181 | #define Z_segSuu (8) // max number of segment pin |
suupen | 0:3df409a1aa42 | 182 | #define Z_grayMax (100) // grayData max 100 kaicho |
suupen | 0:3df409a1aa42 | 183 | #define Z_pwmGrayMax (100) // pwm max (led heno pwm syuturyoku no max) |
suupen | 0:3df409a1aa42 | 184 | |
suupen | 0:3df409a1aa42 | 185 | uint8_t* A_dotDigitalData; // D_dotDigitalData[Z_comSuu][Z_segSuu] address pointer |
suupen | 0:3df409a1aa42 | 186 | //uint8_t D_dotDigitalData[Z_comSuu][Z_segSuu]; // segment dot digital data 0 :ledOff ,1 : ledOn other:disable (1[s] de henka) |
suupen | 0:3df409a1aa42 | 187 | uint8_t* A_dotGrayData; // D_dotGrayData[Z_comSuu][Z_segSuu] address pointer |
suupen | 0:3df409a1aa42 | 188 | //uint8_t D_dotGrayData[Z_comSuu][Z_segSuu]; // setment dot gray data 0 - 100 (1/1 [%]/count) other:disable example 0:ledOff, 100:led max lighting |
suupen | 0:3df409a1aa42 | 189 | |
suupen | 0:3df409a1aa42 | 190 | uint8_t DT_pwmGray[Z_grayMax + 1]; // gray data kara pwm data heno henkan table |
suupen | 0:3df409a1aa42 | 191 | |
suupen | 0:3df409a1aa42 | 192 | uint8_t D_dotPwmData[Z_comSuu][Z_segSuu]; // pwm output data 0 - 100 (1/1 [%]/count) example 0:ledOff, 100:led max lighting |
suupen | 0:3df409a1aa42 | 193 | |
suupen | 0:3df409a1aa42 | 194 | uint8_t D_comNull; // comX Null check No set (0:all com is NC 1:com1 connect, 2:com2 connect,...,8:com8 connect(all com connect) |
suupen | 0:3df409a1aa42 | 195 | |
suupen | 0:3df409a1aa42 | 196 | uint8_t D_commonOn; // common On level set 0:Anode common 1:Cathode common |
suupen | 0:3df409a1aa42 | 197 | uint8_t D_commonOff; |
suupen | 0:3df409a1aa42 | 198 | |
suupen | 0:3df409a1aa42 | 199 | uint8_t D_segmentOn; // segment On level set 0:Cathode common 1:Anode common |
suupen | 0:3df409a1aa42 | 200 | uint8_t D_segmentOff; |
suupen | 0:3df409a1aa42 | 201 | }; |
suupen | 0:3df409a1aa42 | 202 | |
suupen | 0:3df409a1aa42 | 203 | #endif // _EIGHTDOTMATRIXLED_H |