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