Update
Dependents: 16A_Autopancakemaker DigitDisplay_Clock TALab3BDigiDisplayECE595
DigitDisplay.h@0:b593c32bb21f, 2015-12-12 (annotated)
- Committer:
- pruek
- Date:
- Sat Dec 12 07:40:09 2015 +0000
- Revision:
- 0:b593c32bb21f
Update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pruek | 0:b593c32bb21f | 1 | /* The library of Grove - 4 Digit Display |
pruek | 0:b593c32bb21f | 2 | * |
pruek | 0:b593c32bb21f | 3 | * \author Yihui Xiong |
pruek | 0:b593c32bb21f | 4 | * \date 2014/2/8 |
pruek | 0:b593c32bb21f | 5 | * |
pruek | 0:b593c32bb21f | 6 | * The MIT License (MIT) |
pruek | 0:b593c32bb21f | 7 | * |
pruek | 0:b593c32bb21f | 8 | * Copyright (c) 2014 Seeed Technology Inc. |
pruek | 0:b593c32bb21f | 9 | * |
pruek | 0:b593c32bb21f | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
pruek | 0:b593c32bb21f | 11 | * of this software and associated documentation files (the "Software"), to deal |
pruek | 0:b593c32bb21f | 12 | * in the Software without restriction, including without limitation the rights |
pruek | 0:b593c32bb21f | 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
pruek | 0:b593c32bb21f | 14 | * copies of the Software, and to permit persons to whom the Software is |
pruek | 0:b593c32bb21f | 15 | * furnished to do so, subject to the following conditions: |
pruek | 0:b593c32bb21f | 16 | * |
pruek | 0:b593c32bb21f | 17 | * The above copyright notice and this permission notice shall be included in |
pruek | 0:b593c32bb21f | 18 | * all copies or substantial portions of the Software. |
pruek | 0:b593c32bb21f | 19 | * |
pruek | 0:b593c32bb21f | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
pruek | 0:b593c32bb21f | 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
pruek | 0:b593c32bb21f | 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
pruek | 0:b593c32bb21f | 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
pruek | 0:b593c32bb21f | 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
pruek | 0:b593c32bb21f | 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
pruek | 0:b593c32bb21f | 26 | * THE SOFTWARE. |
pruek | 0:b593c32bb21f | 27 | */ |
pruek | 0:b593c32bb21f | 28 | |
pruek | 0:b593c32bb21f | 29 | #ifndef __DIGIT_DISPLAY__ |
pruek | 0:b593c32bb21f | 30 | #define __DIGIT_DISPLAY__ |
pruek | 0:b593c32bb21f | 31 | |
pruek | 0:b593c32bb21f | 32 | #include "mbed.h" |
pruek | 0:b593c32bb21f | 33 | |
pruek | 0:b593c32bb21f | 34 | class DigitDisplay |
pruek | 0:b593c32bb21f | 35 | { |
pruek | 0:b593c32bb21f | 36 | public: |
pruek | 0:b593c32bb21f | 37 | DigitDisplay(PinName clk, PinName dio); |
pruek | 0:b593c32bb21f | 38 | |
pruek | 0:b593c32bb21f | 39 | /** |
pruek | 0:b593c32bb21f | 40 | * Display a decimal number, A number larger than 10000 or smaller than -1000 will be truncated, MSB will be lost. |
pruek | 0:b593c32bb21f | 41 | */ |
pruek | 0:b593c32bb21f | 42 | void write(int16_t number); |
pruek | 0:b593c32bb21f | 43 | |
pruek | 0:b593c32bb21f | 44 | /** |
pruek | 0:b593c32bb21f | 45 | * Display four numbers |
pruek | 0:b593c32bb21f | 46 | * \param numbers 0 - 0xF: 0 - 9, A, b, C, d, E, F |
pruek | 0:b593c32bb21f | 47 | * 0x10 - 0xFE: '_'(unknown) |
pruek | 0:b593c32bb21f | 48 | * 0xFF: ' '(null) |
pruek | 0:b593c32bb21f | 49 | */ |
pruek | 0:b593c32bb21f | 50 | void write(uint8_t numbers[]); |
pruek | 0:b593c32bb21f | 51 | |
pruek | 0:b593c32bb21f | 52 | /** |
pruek | 0:b593c32bb21f | 53 | * Display a number in a specific position |
pruek | 0:b593c32bb21f | 54 | * \param position 0 - 3, left to right |
pruek | 0:b593c32bb21f | 55 | * \param number 0 - 0xF: 0 - 9, A, b, C, d, E, F |
pruek | 0:b593c32bb21f | 56 | * 0x10 - 0xFE: '_' |
pruek | 0:b593c32bb21f | 57 | * 0xFF: ' ' |
pruek | 0:b593c32bb21f | 58 | */ |
pruek | 0:b593c32bb21f | 59 | void write(uint8_t position, uint8_t number); |
pruek | 0:b593c32bb21f | 60 | |
pruek | 0:b593c32bb21f | 61 | void writeRaw(uint8_t position, uint8_t segments); |
pruek | 0:b593c32bb21f | 62 | void writeRaw(uint8_t segments[]); |
pruek | 0:b593c32bb21f | 63 | |
pruek | 0:b593c32bb21f | 64 | void clear(); |
pruek | 0:b593c32bb21f | 65 | void on(); |
pruek | 0:b593c32bb21f | 66 | void off(); |
pruek | 0:b593c32bb21f | 67 | |
pruek | 0:b593c32bb21f | 68 | /** |
pruek | 0:b593c32bb21f | 69 | * Set the brightness, level 0 to level 7 |
pruek | 0:b593c32bb21f | 70 | */ |
pruek | 0:b593c32bb21f | 71 | void setBrightness(uint8_t brightness); |
pruek | 0:b593c32bb21f | 72 | |
pruek | 0:b593c32bb21f | 73 | /** |
pruek | 0:b593c32bb21f | 74 | * Enable/Disable the colon |
pruek | 0:b593c32bb21f | 75 | */ |
pruek | 0:b593c32bb21f | 76 | void setColon(bool enable); |
pruek | 0:b593c32bb21f | 77 | |
pruek | 0:b593c32bb21f | 78 | DigitDisplay& operator= (int16_t number) { |
pruek | 0:b593c32bb21f | 79 | write(number); |
pruek | 0:b593c32bb21f | 80 | return *this; |
pruek | 0:b593c32bb21f | 81 | } |
pruek | 0:b593c32bb21f | 82 | |
pruek | 0:b593c32bb21f | 83 | private: |
pruek | 0:b593c32bb21f | 84 | void start(); |
pruek | 0:b593c32bb21f | 85 | bool send(uint8_t data); |
pruek | 0:b593c32bb21f | 86 | void stop(); |
pruek | 0:b593c32bb21f | 87 | |
pruek | 0:b593c32bb21f | 88 | DigitalOut _clk; |
pruek | 0:b593c32bb21f | 89 | DigitalInOut _dio; |
pruek | 0:b593c32bb21f | 90 | bool _off; |
pruek | 0:b593c32bb21f | 91 | bool _colon; |
pruek | 0:b593c32bb21f | 92 | uint8_t _brightness; |
pruek | 0:b593c32bb21f | 93 | uint8_t _content[4]; |
pruek | 0:b593c32bb21f | 94 | }; |
pruek | 0:b593c32bb21f | 95 | |
pruek | 0:b593c32bb21f | 96 | #endif // __DIGIT_DISPLAY__ |