GY-63_MS5611/libraries/HT16K33/HT16K33.h

174 lines
5.0 KiB
C
Raw Normal View History

2020-07-17 06:34:54 -04:00
#pragma once
//
// FILE: HT16K33.h
// AUTHOR: Rob Tillaart
2024-01-05 03:48:36 -05:00
// VERSION: 0.4.1
// DATE: 2019-02-07
2020-07-17 06:34:54 -04:00
// PURPOSE: Arduino Library for HT16K33 4x7segment display
// http://www.adafruit.com/products/1002
2020-07-17 06:34:54 -04:00
// URL: https://github.com/RobTillaart/HT16K33.git
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
#include "Wire.h"
2021-01-29 06:31:58 -05:00
2024-01-05 03:48:36 -05:00
#define HT16K33_LIB_VERSION (F("0.4.1"))
2021-01-29 06:31:58 -05:00
2024-01-05 03:48:36 -05:00
// Supported characters
2021-01-29 06:31:58 -05:00
#define HT16K33_0 0
#define HT16K33_1 1
#define HT16K33_2 2
#define HT16K33_3 3
#define HT16K33_4 4
#define HT16K33_5 5
#define HT16K33_6 6
#define HT16K33_7 7
#define HT16K33_8 8
#define HT16K33_9 9
#define HT16K33_A 10
#define HT16K33_B 11
#define HT16K33_C 12
#define HT16K33_D 13
#define HT16K33_E 14
#define HT16K33_F 15
#define HT16K33_SPACE 16
#define HT16K33_MINUS 17
2022-11-20 04:12:01 -05:00
#define HT16K33_TOP_C 18 // c
#define HT16K33_DEGREE 19 // °
2021-01-29 06:31:58 -05:00
#define HT16K33_NONE 99
2024-01-05 03:48:36 -05:00
// Raw segments, See #28
//
// HEX codes 7 segment
//
// A 0x01
// F B 0x20 0x02
// G 0x40
// E C 0x10 0x04
// D dp 0x08 0x80
//
const uint8_t SEG_NONE = 0x00;
const uint8_t SEG_A = 0x01;
const uint8_t SEG_B = 0x02;
const uint8_t SEG_C = 0x04;
const uint8_t SEG_D = 0x08;
const uint8_t SEG_E = 0x10;
const uint8_t SEG_F = 0x20;
const uint8_t SEG_G = 0x40;
const uint8_t SEG_DP = 0x80;
class HT16K33
{
2020-07-17 06:34:54 -04:00
public:
2023-02-26 13:22:10 -05:00
HT16K33(const uint8_t address, TwoWire *wire = &Wire); // 0x70 .. 0x77
2020-07-17 06:34:54 -04:00
2023-02-26 13:22:10 -05:00
bool begin();
void reset();
bool isConnected();
2021-01-29 06:31:58 -05:00
2022-11-09 08:38:27 -05:00
// default _cache is true as it is ~3x faster but if one has noise
// on the I2C and wants to force refresh one can disable caching
// for one or more calls.
2023-02-26 13:22:10 -05:00
void clearCache();
void cacheOn();
void cacheOff();
void refresh(); // force writing of cache to display
2021-12-19 09:24:23 -05:00
2023-02-26 13:22:10 -05:00
void displayOn();
void displayOff();
2020-07-17 06:34:54 -04:00
2023-12-05 14:32:12 -05:00
void setBrightness(uint8_t value); // 0 .. 15
2023-02-26 13:22:10 -05:00
uint8_t getBrightness();
2023-12-05 14:32:12 -05:00
void setBlink(uint8_t value); // 0 .. 3 0 = off
uint8_t getBlink();
2020-07-17 06:34:54 -04:00
2021-01-29 06:31:58 -05:00
2022-11-09 08:38:27 -05:00
// 0,1,2,3,4 digits - will replace suppressLeadingZeroPlaces
2023-02-26 13:22:10 -05:00
void setDigits(uint8_t value);
2023-12-05 14:32:12 -05:00
uint8_t getDigits();
2023-02-26 13:22:10 -05:00
void displayClear();
bool displayInt(int n); // -999 .. 9999
bool displayHex(uint16_t n); // 0000 .. FFFF
2020-11-27 05:16:22 -05:00
2022-11-09 08:38:27 -05:00
// Date could be {month.day} or {day.hour} . as separator
// Time could be hh:mm or mm:ss or ss:uu (hundreds : as separator
// colon displays : lz = Leading Zero or space
2023-02-26 13:22:10 -05:00
bool displayDate(uint8_t left, uint8_t right, bool lz = true); // 00.00 .. 99.99
bool displayTime(uint8_t left, uint8_t right, bool colon = true, bool lz = true); // 00:00 .. 99:99
bool displaySeconds(uint16_t seconds, bool colon = true, bool lz = true); // 00:00 .. 99:99
2021-01-29 06:31:58 -05:00
2022-11-20 04:12:01 -05:00
// -999 .. 0.000 .. 9999
2023-02-26 13:22:10 -05:00
bool displayFloat(float f, uint8_t decimals = 3);
2022-11-20 04:12:01 -05:00
// -99 .. 0.00 .. 999
2023-02-26 13:22:10 -05:00
bool displayUnit(float f, uint8_t decimals = 2, uint8_t unitChar = HT16K33_SPACE);
2022-11-20 04:12:01 -05:00
2020-07-17 06:34:54 -04:00
2023-02-26 13:22:10 -05:00
void display(uint8_t *array); // array with 4 elements
void display(uint8_t *array, uint8_t point); // point = digit with . (0..3)
void displayColon(uint8_t on); // 0 = off
void displayRaw(uint8_t *array, bool colon = false); // max control
2022-09-24 04:03:14 -04:00
// from issue #21 - used in special layout :88:8'8 normal = 88:88 or 8.8.8.8
// value = 0 ==> all off.
// 2 = colon
// 4 = upper left point, left of the 1st digit
// 8 = lower left point, left of the 1st digit
// 16 = upper point between 3rd and 4th digit
2023-02-26 13:22:10 -05:00
void displayExtraLeds(uint8_t value);
2022-09-24 04:03:14 -04:00
2023-02-26 13:22:10 -05:00
bool displayVULeft(uint8_t value); // 0..8
bool displayVURight(uint8_t value); // 0..8
2021-01-29 06:31:58 -05:00
2022-11-09 08:38:27 -05:00
// DEBUG
2021-01-29 06:31:58 -05:00
void displayTest(uint8_t del);
2022-11-09 08:38:27 -05:00
// array as numbers
2021-12-19 09:24:23 -05:00
void dumpSerial(uint8_t *array, uint8_t point);
2022-11-09 08:38:27 -05:00
// display cache in HEX format
2021-12-19 09:24:23 -05:00
void dumpSerial();
2023-02-26 13:22:10 -05:00
uint8_t getAddress();
2020-11-27 05:16:22 -05:00
2022-11-09 08:38:27 -05:00
// EXPERIMENTAL
2021-01-29 06:31:58 -05:00
bool displayFixedPoint0(float f);
bool displayFixedPoint1(float f);
bool displayFixedPoint2(float f);
bool displayFixedPoint3(float f);
2023-02-26 13:22:10 -05:00
// use setDigits(); instead.
// 0 = off, 1,2,3,4 digits space instead of 0
2023-12-05 14:32:12 -05:00
void suppressLeadingZeroPlaces(uint8_t value);
// OBSOLETE 0.4.x
void brightness(uint8_t value) { setBrightness(value); };
void blink(uint8_t value) { setBlink(value); };
2023-02-26 13:22:10 -05:00
2021-01-29 06:31:58 -05:00
private:
void _refresh();
void writeCmd(uint8_t cmd);
void writePos(uint8_t pos, uint8_t mask);
2021-12-19 09:24:23 -05:00
void writePos(uint8_t pos, uint8_t mask, bool point);
2021-12-19 09:24:23 -05:00
uint8_t _address;
2022-11-09 08:38:27 -05:00
uint8_t _displayCache[5]; // for performance
2020-11-27 05:16:22 -05:00
bool _cache = true;
uint8_t _digits = 0;
2020-07-17 06:34:54 -04:00
uint8_t _bright;
2023-12-05 14:32:12 -05:00
uint8_t _blink;
2021-01-29 06:31:58 -05:00
TwoWire* _wire;
};
2021-12-19 09:24:23 -05:00
2023-02-26 13:22:10 -05:00
// -- END OF FILE --
2021-12-19 09:24:23 -05:00