├── LICENSE.txt ├── README.md ├── examples └── TM1650_example01 │ └── TM1650_example01.ino ├── keywords.txt ├── library.properties └── src └── TM1650.h /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Anatoli Arkhipenko. 2 | All rights reserved. 3 | 4 | THIS SOFTWARE IS PROVIDED FREE OF CHARGE ACCORDING TO BSD LICENSE: 5 | 6 | Redistribution and use in source and binary forms are permitted 7 | provided that the above copyright notice and this paragraph are 8 | duplicated in all such forms and that any documentation, 9 | advertising materials, and other materials related to such 10 | distribution and use acknowledge that the software was developed 11 | by Anatoli Arkhipenko. The name of the auther may not be used 12 | to endorse or promote products derived from this software without 13 | specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 16 | IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TM1650 2 | 3 | ### 7 segment display driver for JY-MCU module based on TM1650 chip 4 | 5 | ##### Copyright (c) 2015 Anatoli Arkhipenko 6 | 7 | [![arduino-library-badge](https://www.ardu-badge.com/badge/TM1650.svg?)](https://www.ardu-badge.com/TM1650) 8 | 9 | 10 | 11 | ###### Changelog: 12 | 13 | v1.0.0: 14 | 15 | - 2015-02-24 - Initial release 16 | 17 | v1.0.1: 18 | 19 | - 2015-04-27 - Added support of program memery (PROGMEM) to store the ASCII to Segment Code table 20 | 21 | v1.0.2 22 | 23 | - 2015-08-08 - Added check if panel is connected during init. All calls will be disabled is panel was not connected during init. 24 | 25 | v1.1.0: 26 | 27 | - 2015-12-20 - Code clean up. Moved to a single header file. Added Gradual brightness method 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /examples/TM1650_example01/TM1650_example01.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | TM1650 d; 5 | 6 | void setup() 7 | { 8 | Wire.begin(); //Join the bus as master 9 | 10 | Serial.begin(38400); //Start serial communication at 9600 for debug statements 11 | Serial.println("TM1650 Example Code"); 12 | 13 | d.init(); 14 | 15 | } 16 | 17 | void loop() 18 | { 19 | d.displayOff(); 20 | d.displayString("____"); 21 | d.setBrightness(TM1650_MIN_BRIGHT); 22 | d.displayOn(); 23 | delay(100); 24 | char line[] = "1234"; 25 | 26 | d.displayString(line); 27 | d.setBrightnessGradually(TM1650_MAX_BRIGHT); 28 | delay(2000); 29 | d.setBrightnessGradually(TM1650_MIN_BRIGHT); 30 | d.displayOff(); 31 | delay(1000); 32 | 33 | line[1] |= 128; 34 | d.displayOn(); 35 | d.setBrightnessGradually(TM1650_MAX_BRIGHT); 36 | d.displayString(line); 37 | delay(2000); 38 | 39 | // for (int i=0; i<8; i++) { 40 | // d.setBrightness(i); 41 | // delay(500); 42 | // } 43 | 44 | d.displayString("abcd"); 45 | delay(2000); 46 | 47 | d.displayString("789 "); 48 | delay(2000); 49 | 50 | if (d.displayRunning("1234567890abcdefghijklmnop")) { 51 | while (d.displayRunningShift()) delay(500); 52 | } 53 | delay(2000); 54 | 55 | for (int i = 0; i<20; i++) { 56 | d.displayOff(); 57 | delay(200); 58 | d.displayOn(); 59 | delay(200); 60 | } 61 | 62 | for (int i = 0; i<20; i++) { 63 | d.setBrightness(1); 64 | delay(200); 65 | d.setBrightness(7); 66 | delay(200); 67 | } 68 | 69 | for (int i = 0; i<20; i++) { 70 | for (int j = 0; j<4; j++) { 71 | d.setDot(j,true); 72 | delay(200); 73 | } 74 | for (int j = 0; j<4; j++) { 75 | d.setDot(j,false); 76 | delay(200); 77 | } 78 | } 79 | 80 | 81 | } 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For TaskManager 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | TM1650 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | init KEYWORD2 16 | clear KEYWORD2 17 | displayOn KEYWORD2 18 | displayOff KEYWORD2 19 | displayState KEYWORD2 20 | displayString KEYWORD2 21 | displayRunning KEYWORD2 22 | displayRunningShift KEYWORD2 23 | setBrightness KEYWORD2 24 | setBrightnessGradually KEYWORD2 25 | getBrightness KEYWORD2 26 | controlPosition KEYWORD2 27 | setPosition KEYWORD2 28 | setDot KEYWORD2 29 | getPosition KEYWORD2 30 | getNumPositions KEYWORD2 31 | 32 | ####################################### 33 | # Constants (LITERAL1) 34 | ####################################### 35 | 36 | TM1650_MIN_BRIGHT LITERAL1 37 | TM1650_MAX_BRIGHT LITERAL1 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=TM1650 2 | version=1.1.0 3 | author=Anatoli Arkhipenko 4 | maintainer=Anatoli Arkhipenko 5 | sentence=7 segment display driver for JY-MCU module based on TM1650 chip. 6 | paragraph=Allows control of JY-MCU 7 segment display modules based on TM1650 chip. 7 | category=Device Control 8 | url=https://github.com/arkhipenko/TM1650.git 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/TM1650.h: -------------------------------------------------------------------------------- 1 | /** ============================================ 2 | * 7 segment display driver for JY-MCU module based on TM1650 chip 3 | * Copyright (c) 2015 Anatoli Arkhipenko 4 | * 5 | * 6 | * Changelog: 7 | * v1.0.0: 8 | * 2015-02-24 - Initial release 9 | * 10 | * v1.0.1: 11 | * 2015-04-27 - Added support of program memery (PROGMEM) to store the ASCII to Segment Code table 12 | * 13 | * v1.0.2: 14 | * 2015-08-08 - Added check if panel is connected during init. All calls will be disabled is panel was not connected during init. 15 | * 16 | * v1.1.0: 17 | * 2015-12-20 - code clean up. Moved to a single header file. Added Gradual brightness method 18 | * 19 | * ===============================================*/ 20 | 21 | #include 22 | #include 23 | 24 | 25 | #ifndef _TM1650_H_ 26 | #define _TM1650_H_ 27 | 28 | //#define TM1650_USE_PROGMEM 29 | 30 | #ifdef TM1650_USE_PROGMEM 31 | #if (defined(__AVR__)) 32 | #include 33 | #else 34 | #include 35 | #endif 36 | #endif 37 | 38 | #define TM1650_DISPLAY_BASE 0x34 // Address of the left-most digit 39 | #define TM1650_DCTRL_BASE 0x24 // Address of the control register of the left-most digit 40 | #define TM1650_NUM_DIGITS 16 // max number of digits 41 | #define TM1650_MAX_STRING 128 // number of digits 42 | 43 | #define TM1650_BIT_ONOFF 0b00000001 44 | #define TM1650_MSK_ONOFF 0b11111110 45 | #define TM1650_BIT_DOT 0b00000001 46 | #define TM1650_MSK_DOT 0b11110111 47 | #define TM1650_BRIGHT_SHIFT 4 48 | #define TM1650_MSK_BRIGHT 0b10001111 49 | #define TM1650_MIN_BRIGHT 0 50 | #define TM1650_MAX_BRIGHT 7 51 | 52 | #ifndef TM1650_USE_PROGMEM 53 | const byte TM1650_CDigits[128] { 54 | #else 55 | const PROGMEM byte TM1650_CDigits[128] { 56 | #endif 57 | //0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F 58 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x00 59 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 0x10 60 | 0x00, 0x82, 0x21, 0x00, 0x00, 0x00, 0x00, 0x02, 0x39, 0x0F, 0x00, 0x00, 0x00, 0x40, 0x80, 0x00, // 0x20 61 | 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7f, 0x6f, 0x00, 0x00, 0x00, 0x48, 0x00, 0x53, // 0x30 62 | 0x00, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71, 0x6F, 0x76, 0x06, 0x1E, 0x00, 0x38, 0x00, 0x54, 0x3F, // 0x40 63 | 0x73, 0x67, 0x50, 0x6D, 0x78, 0x3E, 0x00, 0x00, 0x00, 0x6E, 0x00, 0x39, 0x00, 0x0F, 0x00, 0x08, // 0x50 64 | 0x63, 0x5F, 0x7C, 0x58, 0x5E, 0x7B, 0x71, 0x6F, 0x74, 0x02, 0x1E, 0x00, 0x06, 0x00, 0x54, 0x5C, // 0x60 65 | 0x73, 0x67, 0x50, 0x6D, 0x78, 0x1C, 0x00, 0x00, 0x00, 0x6E, 0x00, 0x39, 0x30, 0x0F, 0x00, 0x00 // 0x70 66 | }; 67 | 68 | class TM1650 { 69 | public: 70 | TM1650(unsigned int aNumDigits = 4); 71 | 72 | void init(); 73 | void clear(); 74 | void displayOn(); 75 | void displayOff(); 76 | void displayState(bool aState); 77 | void displayString(char *aString); 78 | int displayRunning(char *aString); 79 | int displayRunningShift(); 80 | void setBrightness(unsigned int aValue = TM1650_MAX_BRIGHT); 81 | void setBrightnessGradually(unsigned int aValue = TM1650_MAX_BRIGHT); 82 | inline unsigned int getBrightness() { return iBrightness; }; 83 | 84 | void controlPosition(unsigned int aPos, byte aValue); 85 | void setPosition(unsigned int aPos, byte aValue); 86 | void setDot(unsigned int aPos, bool aState); 87 | byte getPosition(unsigned int aPos) { return iBuffer[aPos]; }; 88 | inline unsigned int getNumPositions() { return iNumDigits; }; 89 | 90 | private: 91 | char *iPosition; 92 | bool iActive; 93 | unsigned int iNumDigits; 94 | unsigned int iBrightness; 95 | char iString[TM1650_MAX_STRING+1]; 96 | byte iBuffer[TM1650_NUM_DIGITS+1]; 97 | byte iCtrl[TM1650_NUM_DIGITS]; 98 | }; 99 | 100 | // ---- Implementation ---- 101 | 102 | /** Constructor, uses default values for the parameters 103 | * so could be called with no parameters. 104 | * aNumDigits - number of display digits (default = 4) 105 | */ 106 | TM1650::TM1650(unsigned int aNumDigits) { 107 | iNumDigits = (aNumDigits > TM1650_NUM_DIGITS) ? TM1650_NUM_DIGITS : aNumDigits; 108 | } 109 | 110 | /** Initialization 111 | * initializes the driver. Turns display on, but clears all digits. 112 | */ 113 | void TM1650::init() { 114 | iPosition = NULL; 115 | for (int i=0; i TM1650_MAX_BRIGHT) ? TM1650_MAX_BRIGHT : aValue; 132 | 133 | for (int i=0; i TM1650_MAX_BRIGHT) aValue = TM1650_MAX_BRIGHT; 148 | int step = (aValue < iBrightness) ? -1 : 1; 149 | unsigned int i = iBrightness; 150 | do { 151 | setBrightness(i); 152 | delay(50); 153 | i += step; 154 | } while (i!=aValue); 155 | } 156 | 157 | /** Turns display on or off according to aState 158 | */ 159 | void TM1650::displayState (bool aState) 160 | { 161 | if (aState) displayOn (); 162 | else displayOff(); 163 | } 164 | 165 | /** Turns the display on 166 | */ 167 | void TM1650::displayOn () 168 | // turn all digits on 169 | { 170 | if (!iActive) return; 171 | for (int i=0; i