├── README.md ├── LICENSE ├── examples ├── MillisDisplay │ └── MillisDisplay.ino ├── FloatDisplay │ └── FloatDisplay.ino └── SimpleDisplay │ └── SimpleDisplay.ino ├── TM1637_6D.h └── TM1637_6D.cpp /README.md: -------------------------------------------------------------------------------- 1 | # TM1637_6D 2 | Arduino library for the 6 digit TM1637 based segment displays 3 | 4 | Wiring:
5 | Arduino Uno ------- 7-Segment module
6 | ===================================
7 | 5V ---------------------> VCC
8 | GND ---------------------> GND
9 | Digital Pin 3 -----------> DIO
10 | Digital Pin 2 -----------> CLK
11 | 12 | # Installation instructions: 13 | 14 | 1. Download this library (Clone or Download --> Download ZIP) 15 | 2. Extract the downloaded zipped library 16 | 3. Put the library folder in the Arduino libraries folder on your computer (for Windows: C:\Users\USERNAME\Documents\Arduino) 17 | 4. Open the Arduino IDE(or restart the Arduino IDE) 18 | 5. Go to examples and you'll find the name of the folder(TM1637_6D-master probably) along with the examples 19 | 6. Have fun! 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 TinyTronics 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/MillisDisplay/MillisDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Example for 6-digit TM1637 based segment Display 3 | * The number of milliseconds after start will be displayed on the 6-digit screen 4 | * 5 | * The MIT License (MIT) 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | #include "TM1637_6D.h" 27 | 28 | #define CLK 3 //pins definitions for TM1637 and can be changed to other ports 29 | #define DIO 2 30 | 31 | TM1637_6D tm1637_6D(CLK,DIO); 32 | 33 | void setup() 34 | { 35 | tm1637_6D.init(); 36 | // You can set the brightness level from 0(darkest) till 7(brightest) or use one 37 | // of the predefined brightness levels below 38 | tm1637_6D.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; 39 | } 40 | void loop() 41 | { 42 | // Print millis to the display 43 | tm1637_6D.displayInteger(millis(), false); // don't add leading zeros 44 | // Execute this loop every 10 milliseconds 45 | delay(10); 46 | } -------------------------------------------------------------------------------- /examples/FloatDisplay/FloatDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Example for 6-digit TM1637 based segment Display 3 | * The number of milliseconds after start will be displayed on the 6-digit screen 4 | * 5 | * The MIT License (MIT) 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | #include "TM1637_6D.h" 27 | 28 | #define CLK 3 //pins definitions for TM1637 and can be changed to other ports 29 | #define DIO 2 30 | 31 | TM1637_6D tm1637_6D(CLK,DIO); 32 | 33 | void setup() 34 | { 35 | tm1637_6D.init(); 36 | // You can set the brightness level from 0(darkest) till 7(brightest) or use one 37 | // of the predefined brightness levels below 38 | tm1637_6D.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; 39 | } 40 | void loop() 41 | { 42 | // Print random float values to the display 43 | tm1637_6D.displayFloat(-1.2345); 44 | delay(2000); 45 | tm1637_6D.displayFloat(987.2345); 46 | delay(2000); 47 | tm1637_6D.displayFloat(1.2345); 48 | delay(2000); 49 | tm1637_6D.displayFloat(192837); 50 | delay(2000); 51 | tm1637_6D.displayFloat(0); 52 | delay(2000); 53 | } -------------------------------------------------------------------------------- /examples/SimpleDisplay/SimpleDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Example for 6-digit TM1637 based segment Display 3 | * The number of milliseconds after start will be displayed on the 6-digit screen 4 | * 5 | * The MIT License (MIT) 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | #include "TM1637_6D.h" 27 | 28 | #define CLK 3 //pins definitions for TM1637 and can be changed to other ports 29 | #define DIO 2 30 | 31 | TM1637_6D tm1637_6D(CLK,DIO); 32 | 33 | void setup() 34 | { 35 | tm1637_6D.init(); 36 | // You can set the brightness level from 0(darkest) till 7(brightest) or use one 37 | // of the predefined brightness levels below 38 | tm1637_6D.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7; 39 | } 40 | void loop() 41 | { 42 | // Array for displaying digits, the first number in the array will be displayed on the right 43 | int8_t ListDisp[6] = {0,1,2,3,4,5}; 44 | // Array for displaying points, the first point in the array will be displayed on the right 45 | int8_t ListDispPoint[6] = {POINT_ON,POINT_OFF,POINT_OFF,POINT_OFF,POINT_OFF,POINT_OFF}; 46 | // String for converting millis value to seperate characters in the string 47 | String millisstring; 48 | 49 | delay(150); 50 | 51 | while(1) 52 | { 53 | // Change the numbers in the ListDisp array here! 54 | 55 | // We send the entire array to the display along with the points array 56 | tm1637_6D.display(ListDisp, ListDispPoint); 57 | // Execute this loop every 10 milliseconds 58 | delay(10); 59 | } 60 | } -------------------------------------------------------------------------------- /TM1637_6D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * TM1637.h 3 | * A library for the 6 digit TM1637 based segment display 4 | * 5 | * Modified for 6 digits and points by: TinyTronics.nl 6 | * 7 | * Copyright (c) 2012 seeed technology inc. 8 | * Website : www.seeed.cc 9 | * Author : Frankie.Chu 10 | * Create Time: 9 April,2012 11 | * Change Log : 12 | * 13 | * The MIT License (MIT) 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | 34 | #ifndef TM1637_6D_h 35 | #define TM1637_6D_h 36 | #include 37 | #include 38 | //************definitions for TM1637********************* 39 | #define ADDR_AUTO 0x40 40 | #define ADDR_FIXED 0x44 41 | 42 | #define STARTADDR 0xc0 43 | /**** definitions for the clock point of the digit tube *******/ 44 | #define POINT_ON 0x80 45 | #define POINT_OFF 0x00 46 | /**************definitions for brightness***********************/ 47 | #define BRIGHT_DARKEST 0 48 | #define BRIGHT_TYPICAL 2 49 | #define BRIGHTEST 7 50 | 51 | class TM1637_6D 52 | { 53 | public: 54 | uint8_t Cmd_SetData; 55 | uint8_t Cmd_SetAddr; 56 | uint8_t Cmd_DispCtrl; 57 | boolean _PointFlag; //_PointFlag=1:the clock point on 58 | TM1637_6D(uint8_t, uint8_t); 59 | void init(void); //To clear the display 60 | int writeByte(int8_t wr_data);//write 8bit data to tm1637 61 | void start(void);//send start bits 62 | void stop(void); //send stop bits 63 | void display(int8_t DispData[],int8_t DispPointData[]); 64 | void display(uint8_t BitAddr,int8_t DispData,int8_t DispPointData); 65 | void displayError(); 66 | void displayInteger(int32_t intdisplay, bool leading_zeros); 67 | void displayFloat(float floatdisplay); 68 | void clearDisplay(void); 69 | void set(uint8_t = BRIGHT_TYPICAL,uint8_t = 0x40,uint8_t = 0xc0);//To take effect the next time it displays. 70 | void coding(int8_t DispData[],int8_t DispPointData[]); 71 | int8_t coding(int8_t DispData,int8_t DispPointData); 72 | void bitDelay(void); 73 | private: 74 | uint8_t Clkpin; 75 | uint8_t Datapin; 76 | }; 77 | #endif 78 | -------------------------------------------------------------------------------- /TM1637_6D.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * TM1637_6D.cpp 3 | * A library for the 6 digit TM1637 based segment display 4 | * 5 | * Modified for 6 digits and points by: TinyTronics.nl 6 | * 7 | * Copyright (c) 2012 seeed technology inc. 8 | * Website : www.seeed.cc 9 | * Author : Frankie.Chu 10 | * Create Time: 9 April,2012 11 | * Change Log : 12 | * 13 | * The MIT License (MIT) 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | 34 | #include "TM1637_6D.h" 35 | #include 36 | static int8_t TubeTab[] = {0x3f,0x06,0x5b,0x4f, 37 | 0x66,0x6d,0x7d,0x07, 38 | 0x7f,0x6f,0x00,0x40};//0~9, 10=blank digit, 11=dash/minus character 39 | TM1637_6D::TM1637_6D(uint8_t Clk, uint8_t Data) 40 | { 41 | Clkpin = Clk; 42 | Datapin = Data; 43 | pinMode(Clkpin,OUTPUT); 44 | pinMode(Datapin,OUTPUT); 45 | } 46 | 47 | void TM1637_6D::init(void) 48 | { 49 | clearDisplay(); 50 | } 51 | 52 | int TM1637_6D::writeByte(int8_t wr_data) 53 | { 54 | uint8_t i,count1; 55 | for(i=0;i<8;i++) //sent 8bit data 56 | { 57 | digitalWrite(Clkpin,LOW); 58 | if(wr_data & 0x01)digitalWrite(Datapin,HIGH);//LSB first 59 | else digitalWrite(Datapin,LOW); 60 | wr_data >>= 1; 61 | digitalWrite(Clkpin,HIGH); 62 | 63 | } 64 | digitalWrite(Clkpin,LOW); //wait for the ACK 65 | digitalWrite(Datapin,HIGH); 66 | digitalWrite(Clkpin,HIGH); 67 | pinMode(Datapin,INPUT); 68 | 69 | bitDelay(); 70 | uint8_t ack = digitalRead(Datapin); 71 | if (ack == 0) 72 | { 73 | pinMode(Datapin,OUTPUT); 74 | digitalWrite(Datapin,LOW); 75 | } 76 | bitDelay(); 77 | pinMode(Datapin,OUTPUT); 78 | bitDelay(); 79 | 80 | return ack; 81 | } 82 | //send start signal to TM1637 83 | void TM1637_6D::start(void) 84 | { 85 | digitalWrite(Clkpin,HIGH);//send start signal to TM1637 86 | digitalWrite(Datapin,HIGH); 87 | digitalWrite(Datapin,LOW); 88 | digitalWrite(Clkpin,LOW); 89 | } 90 | //End of transmission 91 | void TM1637_6D::stop(void) 92 | { 93 | digitalWrite(Clkpin,LOW); 94 | digitalWrite(Datapin,LOW); 95 | digitalWrite(Clkpin,HIGH); 96 | digitalWrite(Datapin,HIGH); 97 | } 98 | //display function.Write to full-screen. 99 | void TM1637_6D::display(int8_t DispData[], int8_t DispPointData[]) 100 | { 101 | int8_t SegData[6]; 102 | int8_t SegPointData[6]; 103 | int8_t i; 104 | 105 | for(i = 0;i < 6;i++) 106 | { 107 | if(DispData[i] > 11 || DispData[i] < 0) DispData[i] = 11; 108 | } 109 | 110 | SegData[0] = DispData[3]; 111 | SegData[1] = DispData[4]; 112 | SegData[2] = DispData[5]; 113 | SegData[3] = DispData[0]; 114 | SegData[4] = DispData[1]; 115 | SegData[5] = DispData[2]; 116 | 117 | SegPointData[0] = DispPointData[3]; 118 | SegPointData[1] = DispPointData[4]; 119 | SegPointData[2] = DispPointData[5]; 120 | SegPointData[3] = DispPointData[0]; 121 | SegPointData[4] = DispPointData[1]; 122 | SegPointData[5] = DispPointData[2]; 123 | 124 | coding(SegData, SegPointData); 125 | start(); //start signal sent to TM1637 from MCU 126 | writeByte(ADDR_AUTO);// 127 | stop(); // 128 | start(); // 129 | writeByte(Cmd_SetAddr);// 130 | for(i=0;i < 6;i ++) 131 | { 132 | writeByte(SegData[i]); // 133 | } 134 | stop(); // 135 | start(); // 136 | writeByte(Cmd_DispCtrl);// 137 | stop(); // 138 | } 139 | //****************************************** 140 | void TM1637_6D::display(uint8_t BitAddr,int8_t DispData,int8_t DispPointData) 141 | { 142 | int8_t SegData; 143 | SegData = coding(DispData, DispPointData); 144 | start(); //start signal sent to TM1637 from MCU 145 | writeByte(ADDR_FIXED);// 146 | stop(); // 147 | start(); // 148 | writeByte(BitAddr|0xc0);// 149 | writeByte(SegData);// 150 | stop(); // 151 | start(); // 152 | writeByte(Cmd_DispCtrl);// 153 | stop(); // 154 | } 155 | 156 | // Displays 6 dashes are error marker 157 | void TM1637_6D::displayError() 158 | { 159 | int8_t tempListDisp[6] = {11,11,11,11,11,11}; // fill array with dashes character(11th) 160 | int8_t tempListDispPoint[6] = {0x00,0x00,0x00,0x00,0x00,0x00}; // don't show any points 161 | display(tempListDisp, tempListDispPoint); 162 | } 163 | 164 | void TM1637_6D::displayInteger(int32_t intdisplay, bool leading_zeros) 165 | { 166 | int8_t tempListDisp[6] = {10,10,10,10,10,10}; // fill array with value for blank digit 167 | int8_t tempListDispPoint[6] = {0x00,0x00,0x00,0x00,0x00,0x00}; // don't show any points 168 | int8_t i = 0; 169 | // String for converting millis value to seperate characters in the string 170 | String intstring; 171 | 172 | // if the integer is bigger than 6 characters, display an error(dashes) 173 | if(intdisplay > 999999 || intdisplay < -99999) 174 | { 175 | displayError(); 176 | } 177 | else 178 | { 179 | if(intdisplay < 0) 180 | { 181 | intstring = String((intdisplay*-1), DEC); // convertering the inverted integer to a string 182 | if(leading_zeros) 183 | { 184 | intstring = "000000" + intstring; 185 | } // Adding some extra leading zeros 186 | for(i = 0; i < intstring.length(); i++) 187 | { 188 | // number "0" in ASCII is 48 in decimal. If we substract the character value 189 | // with 48, we will get the actual number it is representing as a character 190 | tempListDisp[i] = intstring[intstring.length()-i-1] - 48; 191 | } 192 | tempListDisp[5] = 11;// adding the dash/minus later for this negative integer 193 | } 194 | else 195 | { 196 | intstring = String(intdisplay, DEC); // convertering integer to a string 197 | if(leading_zeros){ intstring = "000000" + intstring;} // Adding some extra leading zeros 198 | for(i = 0; i < intstring.length(); i++) 199 | { 200 | // number "0" in ASCII is 48 in decimal. If we substract the character value 201 | // with 48, we will get the actual number it is representing as a character 202 | tempListDisp[i] = intstring[intstring.length()-i-1] - 48; 203 | } 204 | } 205 | display(tempListDisp, tempListDispPoint); 206 | } 207 | } 208 | 209 | void TM1637_6D::displayFloat(float floatdisplay) 210 | { 211 | int8_t tempListDisp[6] = {10,10,10,10,10,10}; // fill array with value for blank digit 212 | int8_t tempListDispPoint[6] = {0x00,0x00,0x00,0x00,0x00,0x00}; // don't show any points 213 | int8_t i = 0; 214 | // String for converting millis value to seperate characters in the string 215 | String floatstring; 216 | 217 | // if the integer is bigger than 6 characters, display an error(dashes) 218 | if(floatdisplay >= 999999.5 || floatdisplay <= -99999.5) 219 | { 220 | displayError(); 221 | } 222 | else 223 | { 224 | // Calculate how many digits we have before the decimal point 225 | if(floatdisplay < 0) { floatstring = String(floatdisplay*-1.0, 1);} // with one "dummy" decimal 226 | else { floatstring = String(floatdisplay, 1);} // with one "dummy" decimal 227 | for(i = 0; i < floatstring.length(); i++) 228 | { 229 | // check how many digits we have before the decimal point 230 | if(floatstring[i] == '.') break; 231 | } 232 | uint8_t numberofdigits = i; 233 | uint8_t decimal_point_add = 0; // used to skip the decimal point in the string 234 | 235 | if(floatdisplay < 0) 236 | { 237 | floatstring = String((floatdisplay*-1.0), 5-numberofdigits); // convertering the inverted integer to a string 238 | decimal_point_add = 0; 239 | for(i = 0; i < floatstring.length(); i++) 240 | { 241 | // number "0" in ASCII is 48 in decimal. If we substract the character value 242 | // with 48, we will get the actual number it is representing as a character 243 | tempListDisp[i] = floatstring[floatstring.length()-i-1-decimal_point_add] - 48; 244 | if(floatstring[floatstring.length()-i-2] == '.') 245 | { 246 | tempListDispPoint[i+1] = 0x80; // set decimal point 247 | decimal_point_add = 1; 248 | } 249 | 250 | } 251 | tempListDisp[5] = 11;// adding the dash/minus later for this negative integer 252 | } 253 | else 254 | { 255 | floatstring = String(floatdisplay, 6-numberofdigits); // convertering integer to a string 256 | decimal_point_add = 0; 257 | Serial.println(floatstring.length()); 258 | for(i = 0; i < (floatstring.length() - decimal_point_add); i++) 259 | { 260 | 261 | // number "0" in ASCII is 48 in decimal. If we substract the character value 262 | // with 48, we will get the actual number it is representing as a character 263 | tempListDisp[i] = floatstring[floatstring.length()-i-1-decimal_point_add] - 48; 264 | if(floatstring[floatstring.length()-i-2] == '.') 265 | { 266 | tempListDispPoint[i+1] = 0x80; // set decimal point 267 | decimal_point_add = 1; 268 | } 269 | } 270 | } 271 | if(decimal_point_add == 0) tempListDispPoint[0] = 0x80; 272 | display(tempListDisp, tempListDispPoint); 273 | } 274 | } 275 | 276 | void TM1637_6D::clearDisplay(void) 277 | { 278 | int8_t tempListDisp[6] = {10,10,10,10,10,10}; // fill array with dashes character(11th) 279 | int8_t tempListDispPoint[6] = {0x00,0x00,0x00,0x00,0x00,0x00}; // don't show any poinst 280 | display(tempListDisp, tempListDispPoint); 281 | } 282 | //To take effect the next time it displays. 283 | void TM1637_6D::set(uint8_t brightness,uint8_t SetData,uint8_t SetAddr) 284 | { 285 | Cmd_SetData = SetData; 286 | Cmd_SetAddr = SetAddr; 287 | Cmd_DispCtrl = 0x88 + brightness;//Set the brightness and it takes effect the next time it displays. 288 | } 289 | 290 | void TM1637_6D::coding(int8_t DispData[], int8_t DispPointData[]) 291 | { 292 | for(uint8_t i = 0;i < 6;i ++) 293 | { 294 | if(DispData[i] == 0x7f)DispData[i] = 0x00 + DispPointData[i]; 295 | else DispData[i] = TubeTab[DispData[i]] + DispPointData[i]; 296 | } 297 | } 298 | int8_t TM1637_6D::coding(int8_t DispData, int8_t DispPointData) 299 | { 300 | if(DispData == 0x7f) DispData = 0x00 + DispPointData;//The bit digital tube off 301 | else DispData = TubeTab[DispData] + DispPointData; 302 | return DispData; 303 | } 304 | void TM1637_6D::bitDelay(void) 305 | { 306 | delayMicroseconds(50); 307 | } 308 | --------------------------------------------------------------------------------