library for Seeed's Grove - 4 Digit Display

Dependents:   SeeedStudio_Grove_Sensors_Demo thermostat_fan_demo--fan SeeedStudio_Grove_Sensors_Demo microbit-8-ultrasonic-meter ... more

Fork of DigitDisplay by Seeed Studio

Committer:
seeed
Date:
Sat Feb 08 05:42:09 2014 +0000
Revision:
0:d3173c8bfd48
initial

Who changed what in which revision?

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