2021-04-25 13:56:44 -04:00
|
|
|
|
#pragma once
|
|
|
|
|
//
|
|
|
|
|
// FILE: TM1637.h
|
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
|
// DATE: 2019-10-28
|
2023-07-18 09:38:19 -04:00
|
|
|
|
// VERSION: 0.3.8
|
2021-04-25 13:56:44 -04:00
|
|
|
|
// PUPROSE: TM1637 library for Arduino
|
|
|
|
|
// URL: https://github.com/RobTillaart/TM1637_RT
|
|
|
|
|
|
|
|
|
|
|
2023-04-17 07:13:30 -04:00
|
|
|
|
// tested on 6 digit display
|
|
|
|
|
// tested on 4 digit (clock) display esp. displayTime()
|
2021-04-25 13:56:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
|
2023-07-18 09:38:19 -04:00
|
|
|
|
#define TM1637_LIB_VERSION (F("0.3.8"))
|
2021-04-25 13:56:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TM1637
|
|
|
|
|
{
|
2022-09-25 03:59:53 -04:00
|
|
|
|
public:
|
|
|
|
|
TM1637();
|
|
|
|
|
|
|
|
|
|
// replaces init()
|
|
|
|
|
void begin(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);
|
|
|
|
|
|
2023-02-27 14:45:02 -05:00
|
|
|
|
|
|
|
|
|
// DISPLAY FUNCTIONS
|
2022-10-07 05:32:52 -04:00
|
|
|
|
void displayPChar( char * buff );
|
2022-09-25 03:59:53 -04:00
|
|
|
|
void displayRaw(uint8_t * data, uint8_t pointPos);
|
|
|
|
|
void displayInt(long value);
|
|
|
|
|
void displayFloat(float value);
|
2023-02-18 07:28:46 -05:00
|
|
|
|
void displayFloat(float value, uint8_t fixedPoint);
|
2022-09-25 03:59:53 -04:00
|
|
|
|
void displayHex(uint32_t value);
|
2023-07-18 09:38:19 -04:00
|
|
|
|
|
2023-04-17 07:13:30 -04:00
|
|
|
|
|
|
|
|
|
// next 3 only tested on 4 digit display with colon
|
2023-02-27 14:45:02 -05:00
|
|
|
|
void displayTime(uint8_t hh, uint8_t mm, bool colon);
|
2023-04-17 07:13:30 -04:00
|
|
|
|
void displayTwoInt(int ll, int rr, bool colon = true);
|
2023-07-18 09:38:19 -04:00
|
|
|
|
// Celsius -9..99<EFBFBD>C
|
2023-04-17 07:13:30 -04:00
|
|
|
|
void displayCelsius(int temp, bool colon = false);
|
2023-07-18 09:38:19 -04:00
|
|
|
|
// Fahrenheit -9..99<EFBFBD>F
|
|
|
|
|
void displayFahrenheit(int temp, bool colon = false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// DISPLAY FUNCTIONS META
|
|
|
|
|
void displayClear();
|
|
|
|
|
void displayRefresh();
|
|
|
|
|
// EXPERIMENTAL 0.3.8
|
|
|
|
|
void hideSegment(uint8_t idx);
|
|
|
|
|
void hideMultiSegment(uint8_t mask); // 0 bit = show 1 bit = hide
|
2023-02-27 14:45:02 -05:00
|
|
|
|
|
2022-09-25 03:59:53 -04:00
|
|
|
|
|
2023-02-27 14:45:02 -05:00
|
|
|
|
// BRIGHTNESS
|
2023-04-17 07:13:30 -04:00
|
|
|
|
// brightness = 0..7
|
|
|
|
|
void setBrightness(uint8_t brightness = 3); // default 3
|
2023-02-18 07:28:46 -05:00
|
|
|
|
uint8_t getBrightness();
|
2022-09-25 03:59:53 -04:00
|
|
|
|
|
2023-02-27 14:45:02 -05:00
|
|
|
|
|
|
|
|
|
// BIT DELAY
|
2022-09-25 03:59:53 -04:00
|
|
|
|
// tune the timing of writing bytes.
|
2023-04-17 07:13:30 -04:00
|
|
|
|
void setBitDelay(uint8_t bitDelay = 10);
|
|
|
|
|
uint8_t getBitDelay();
|
|
|
|
|
|
2023-02-27 14:45:02 -05:00
|
|
|
|
|
|
|
|
|
// KEY SCAN
|
2022-09-25 03:59:53 -04:00
|
|
|
|
uint8_t keyscan(void);
|
|
|
|
|
|
2023-02-27 14:45:02 -05:00
|
|
|
|
|
|
|
|
|
// CONFIGURATION
|
2022-09-25 03:59:53 -04:00
|
|
|
|
// the order the individual digits must be sent to the display.
|
2023-04-17 07:13:30 -04:00
|
|
|
|
// optionally to be called after begin()
|
2022-09-25 03:59:53 -04:00
|
|
|
|
void setDigitOrder(uint8_t a = 0, uint8_t b = 1,
|
|
|
|
|
uint8_t c = 2, uint8_t d = 3,
|
|
|
|
|
uint8_t e = 4, uint8_t f = 5,
|
|
|
|
|
uint8_t g = 6, uint8_t h = 7);
|
|
|
|
|
|
2023-02-27 14:45:02 -05:00
|
|
|
|
|
2022-09-25 03:59:53 -04:00
|
|
|
|
// OBSOLETE
|
|
|
|
|
// init will be replaced by begin() in the future (0.4.0)
|
|
|
|
|
void init(uint8_t clockPin, uint8_t dataPin, uint8_t digits = 6);
|
|
|
|
|
|
2023-07-18 09:38:19 -04:00
|
|
|
|
// DEBUG only
|
|
|
|
|
void dumpCache();
|
|
|
|
|
|
2022-09-25 03:59:53 -04:00
|
|
|
|
|
|
|
|
|
private:
|
2023-07-18 09:38:19 -04:00
|
|
|
|
uint8_t _clockPin = -1;
|
|
|
|
|
uint8_t _dataPin = -1;
|
2023-04-17 07:13:30 -04:00
|
|
|
|
uint8_t _digits = 6;
|
2022-09-25 03:59:53 -04:00
|
|
|
|
uint8_t _brightness = 3;
|
|
|
|
|
uint8_t _bitDelay = 10;
|
|
|
|
|
|
|
|
|
|
uint8_t _digitOrder[8];
|
|
|
|
|
|
2023-07-18 09:38:19 -04:00
|
|
|
|
uint8_t _data[8];
|
|
|
|
|
uint8_t _lastPointPos;
|
|
|
|
|
|
2022-09-25 03:59:53 -04:00
|
|
|
|
uint8_t writeByte(uint8_t data);
|
|
|
|
|
void start();
|
|
|
|
|
void stop();
|
|
|
|
|
|
2023-07-18 09:38:19 -04:00
|
|
|
|
void writeSync(uint8_t pin, uint8_t val);
|
|
|
|
|
void nanoDelay(uint16_t n);
|
2022-10-07 05:32:52 -04:00
|
|
|
|
|
|
|
|
|
// Override in your own derived class for custom character translation
|
2023-02-18 07:28:46 -05:00
|
|
|
|
virtual uint8_t asciiTo7Segment ( char c ) ;
|
2021-04-25 13:56:44 -04:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-29 06:48:28 -05:00
|
|
|
|
|
2023-02-18 07:28:46 -05:00
|
|
|
|
// -- END OF FILE --
|
2021-12-29 06:48:28 -05:00
|
|
|
|
|