### Setup Function for 6-Digit Display Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/README.md In the setup function, call display.begin() to initialize the 6-digit display. Then, use showString and showNumber to display initial content. ```cpp void setup() { display.begin(); display.showString("digits"); delay(1000); display.showNumber(123456); delay(1000); display.showNumber(123.456); delay(1000); } ``` -------------------------------- ### Example Data Function Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/examples/7-segment-animator.html Loads a predefined example animation sequence into the 'codeOutput' div. It also sets the background color and calls formatData. ```javascript // Load en example animation function exampleData() { var data = " { 0x08, 0x00, 0x00, 0x00 },\n { 0x00, 0x08, 0x00, 0x00 },\n { 0x00, 0x00, 0x08, 0x00 },\n { 0x00, 0x00, 0x00, 0x08 },\n { 0x00, 0x00, 0x00, 0x04 },\n { 0x00, 0x00, 0x00, 0x02 },\n { 0x00, 0x00, 0x00, 0x01 },\n { 0x00, 0x00, 0x01, 0x00 },\n { 0x00, 0x01, 0x00, 0x00 },\n { 0x01, 0x00, 0x00, 0x00 },\n { 0x20, 0x00, 0x00, 0x00 },\n { 0x10, 0x00, 0x00, 0x00 },"; $('#codeOutput').text(data); $("#outputblock").css("background-color","salmon"); formatData(!HGFEDCBA); } ``` -------------------------------- ### Basic TM1637 Display Example Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/README.md This example demonstrates basic usage of the TM1637TinyDisplay library, including initializing the display, showing strings, clearing the screen, displaying numbers, and creating a level indicator. It also shows how to split the screen for displaying numbers and text simultaneously. ```cpp #include #include // Define Digital Pins #define CLK 2 #define DIO 3 // Instantiate TM1637TinyDisplay Class TM1637TinyDisplay display(CLK, DIO); void setup() { // Initialize Display display.begin(); } void loop() { // Say Hello display.showString("HELLO"); delay(500); // Clear Screen display.clear(); // We can count! for (int x = -100; x <= 100; x++) { display.showNumber(x); } // Level indicator for (int x = 0; x <= 100; x = x + 10) { display.showLevel(x, false); delay(20); } for (int x = 100; x >= 0; x = x - 10) { display.showLevel(x, false); delay(20); } // Split screen for temperature display.showString("\xB0", 1, 3); // Degree Mark, length=1, position=3 (right) for (int x = -90; x < 200; x++) { display.showNumber(x, false, 3, 0); // Number, length=3, position=0 (left) delay(10); } // The end display.showString("End"); delay(1000); } ``` -------------------------------- ### Initialize TM1637 Display with Options Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/RELEASE.md Call this method once in setup() before other functions. It initializes the display, allowing optional clearing and setting full brightness. ```cpp void begin(); void begin(bool clearDisplay=true); ``` ```cpp void TM1637TinyDisplay::begin(bool clearDisplay) { // Set the pin direction and default value. // Both pins are set as inputs, allowing the pull-up resistors to pull them up pinMode(m_pinClk, INPUT); pinMode(m_pinDIO, INPUT); digitalWrite(m_pinClk, LOW); digitalWrite(m_pinDIO, LOW); if (clearDisplay) { clear(); setBrightness(BRIGHT_HIGH); } } ``` -------------------------------- ### Show Animation Example Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/examples/README.md Demonstrates how to display a sequence of frames using the showAnimation() function. Requires the TM1637TinyDisplay library and animation data generated by the Animator Tool. ```cpp #include #include // Define Digital Pins #define CLK 4 #define DIO 5 // Initialize TM1637TinyDisplay TM1637TinyDisplay display(CLK, DIO); // Data from Animator Tool const uint8_t ANIMATION[12][4] = { { 0x08, 0x00, 0x00, 0x00 }, // Frame 0 { 0x00, 0x08, 0x00, 0x00 }, // Frame 1 { 0x00, 0x00, 0x08, 0x00 }, // Frame 2 { 0x00, 0x00, 0x00, 0x08 }, // Frame 3 { 0x00, 0x00, 0x00, 0x04 }, // Frame 4 { 0x00, 0x00, 0x00, 0x02 }, // Frame 5 { 0x00, 0x00, 0x00, 0x01 }, // Frame 6 { 0x00, 0x00, 0x01, 0x00 }, // Frame 7 { 0x00, 0x01, 0x00, 0x00 }, // Frame 8 { 0x01, 0x00, 0x00, 0x00 }, // Frame 9 { 0x20, 0x00, 0x00, 0x00 }, // Frame 10 { 0x10, 0x00, 0x00, 0x00 } // Frame 11 }; void setup() { display.setBrightness(0x0f); } void loop() { // Display Animation sequence display.showAnimation(ANIMATION, FRAMES(ANIMATION), TIME_MS(50)); } ``` -------------------------------- ### Initialize TM1637TinyDisplay (4-Digit) Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Instantiate the TM1637TinyDisplay class with CLK and DIO pin numbers. Call `begin()` in setup() to initialize hardware and set default brightness. The display is cleared upon initialization. ```cpp #include #include // Define Digital Pins #define CLK 4 #define DIO 5 // Initialize TM1637TinyDisplay - 4 Digit Display TM1637TinyDisplay display(CLK, DIO); void setup() { // Initialize display - clears screen and sets max brightness display.begin(); // Optionally initialize without clearing/brightness setting // display.begin(false); } void loop() { display.showString("Hi"); delay(1000); } ``` -------------------------------- ### Initialize 6-Digit Display Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/README.md Include the TM1637TinyDisplay6 header and initialize the display object using the CLK and DIO pins. This setup is required for 6-digit modules. ```cpp // Includes #include #include // Include 6-Digit Display Class Header // Define Digital Pins #define CLK 2 #define DIO 3 TM1637TinyDisplay6 display(CLK, DIO); // 6-Digit Display Class ``` -------------------------------- ### Initialize TM1637TinyDisplay6 (6-Digit) Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Use the TM1637TinyDisplay6 class for 6-digit displays, which handles unique digit mapping and reverse data upload. Call `begin()` in setup() to initialize. ```cpp #include #include #define CLK 4 #define DIO 5 // Initialize 6-Digit Display Class TM1637TinyDisplay6 display(CLK, DIO); void setup() { display.begin(); display.showString("digits"); // Display up to 6 characters delay(1000); display.showNumber(123456); // Display 6-digit number delay(1000); display.showNumber(123.456); // Floating point with decimals } void loop() { // Your code here } ``` -------------------------------- ### Non-Blocking Animation with startAnimation Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Starts an animation that runs in the background. Call Animate() regularly in loop() to advance frames. Animations can be started from SRAM or PROGMEM. ```cpp #include TM1637TinyDisplay display(4, 5); const uint8_t LOADING[4][4] = { { 0x08, 0x00, 0x00, 0x00 }, { 0x00, 0x08, 0x00, 0x00 }, { 0x00, 0x00, 0x08, 0x00 }, { 0x00, 0x00, 0x00, 0x08 } }; const uint8_t LOADING_P[4][4] PROGMEM = { { 0x01, 0x00, 0x00, 0x00 }, { 0x00, 0x01, 0x00, 0x00 }, { 0x00, 0x00, 0x01, 0x00 }, { 0x00, 0x00, 0x00, 0x01 } }; int counter = 0; void setup() { Serial.begin(9600); display.begin(); // Start non-blocking animation from SRAM display.startAnimation(LOADING, FRAMES(LOADING), TIME_MS(100)); // Or from PROGMEM // display.startAnimation_P(LOADING_P, FRAMES(LOADING_P), TIME_MS(100)); } void loop() { // Animate() returns true while animation is running bool isRunning = display.Animate(); // Do other work while animating Serial.print("Counter: "); Serial.println(counter++); delay(10); // When animation finishes, start new one or show result if (!isRunning) { display.showString("done"); delay(2000); // Restart with looping enabled display.startAnimation(LOADING, FRAMES(LOADING), TIME_MS(100)); } // Optional: loop animation continuously with Animate(true) // display.Animate(true); // Animation restarts when it ends // Optional: stop animation early // display.stopAnimation(); } ``` -------------------------------- ### Non-Blocking String Scrolling with startStringScroll Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Starts a scrolling text display that runs in the background. Call Animate() regularly to advance the scroll position. Supports strings from SRAM and PROGMEM. ```cpp #include TM1637TinyDisplay display(4, 5); const PROGMEM char flashMessage[] = "Message stored in PROGMEM Flash Memory"; const char ramMessage[] = "Message in SRAM"; void setup() { Serial.begin(9600); display.begin(); // Start non-blocking scroll from SRAM display.startStringScroll(ramMessage, 200); // 200ms per frame } void loop() { // Call Animate() to advance scroll bool isScrolling = display.Animate(); // Do other work while scrolling Serial.println("Working..."); if (!isScrolling) { delay(1000); // Start PROGMEM string scroll display.startStringScroll_P(flashMessage, 150); // Wait for it to finish while (display.Animate()) { // Do other work delay(10); } display.showString("End"); delay(2000); // Restart display.startStringScroll("Loop Test 12345", 200); } } ``` -------------------------------- ### readBuffer - Get Current Display State Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Copies the current display buffer contents for reading or backup purposes. ```APIDOC ## readBuffer ### Description Copies the current display buffer contents for reading or backup purposes. ### Parameters - **buffer** (uint8_t[]) - Required - Array to store the current display state. ``` -------------------------------- ### Constants and Macros Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/keywords.txt Available constants and macros for configuring display behavior and brightness. ```APIDOC ## Constants and Macros ### Brightness Constants - **BRIGHT_LOW, BRIGHT_0 - BRIGHT_7, BRIGHT_HIGH**: Used with setBrightness to control intensity. ### Segment Constants - **SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F, SEG_G, SEG_DP**: Individual segment bitmasks. ### Utility Constants - **MAXDIGITS**: Maximum number of digits supported. - **ON, OFF**: State constants. - **FRAMES, TIME_MS, TIME_S**: Macros for animation timing. ``` -------------------------------- ### Display Strings from PROGMEM Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Use showString_P to display strings stored in flash memory, which is useful for saving RAM on memory-constrained devices like the ATtiny85. ```cpp #include TM1637TinyDisplay display(4, 5); // Store strings in PROGMEM (flash memory) const PROGMEM char message1[] = "Hello World from Flash Memory"; const PROGMEM char message2[] = "Save RAM"; void setup() { display.begin(); // Display PROGMEM string (auto-scrolls if long) display.showString_P(message1); delay(1000); // Short PROGMEM string display.showString_P(message2); delay(2000); // With position and length control // showString_P(string, length, position, dots) display.showString_P(PSTR("TEST"), 4, 0, 0); } void loop() {} ``` -------------------------------- ### Display PROGMEM Animations with showAnimation_P Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Optimizes RAM usage by storing animation frames in flash memory. Requires the PROGMEM keyword for the data array. ```cpp #include TM1637TinyDisplay display(4, 5); // Store animation in PROGMEM to save RAM const uint8_t SPINNER[8][4] PROGMEM = { { 0x01, 0x00, 0x00, 0x00 }, // Top { 0x02, 0x00, 0x00, 0x00 }, // Top-right { 0x04, 0x00, 0x00, 0x00 }, // Bottom-right { 0x08, 0x00, 0x00, 0x00 }, // Bottom { 0x10, 0x00, 0x00, 0x00 }, // Bottom-left { 0x20, 0x00, 0x00, 0x00 }, // Top-left { 0x40, 0x00, 0x00, 0x00 }, // Middle { 0x00, 0x00, 0x00, 0x00 } // Blank }; void setup() { display.begin(); // Play PROGMEM animation display.showAnimation_P(SPINNER, FRAMES(SPINNER), TIME_MS(100)); // Loop animation multiple times for (int i = 0; i < 10; i++) { display.showAnimation_P(SPINNER, 8, 75); } } void loop() {} ``` -------------------------------- ### Countdown Timer Implementation Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Uses split-screen formatting to display minutes and seconds on a 4-digit display. Requires the TM1637TinyDisplay library. ```cpp #include TM1637TinyDisplay display(4, 5); #define SECS_PER_MIN 60UL #define SECS_PER_HOUR 3600UL unsigned long startTime; unsigned long countDown; void setup() { display.begin(); startTime = millis(); // Set countdown: 1 hour, 30 minutes, 0 seconds int hours = 0, mins = 1, secs = 30; countDown = ((hours * SECS_PER_HOUR) + (mins * SECS_PER_MIN) + secs) * 1000UL; } void loop() { unsigned long elapsed = millis() - startTime; if (elapsed >= countDown) { // Timer finished - flash zeros if ((millis() / 500) % 2) { display.clear(); } else { display.showNumberDec(0, 0b01000000, true); // 00:00 } } else { unsigned long remaining = (countDown - elapsed) / 1000; unsigned long mins = (remaining / 60) % 60; unsigned long secs = remaining % 60; // Display MM:SS with colon display.showNumberDec(mins, 0b01000000, true, 2, 0); // Minutes left display.showNumberDec(secs, 0b01000000, true, 2, 2); // Seconds right } delay(100); } ``` -------------------------------- ### Display Text Strings Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Use showString to display ASCII text. Strings longer than the display width will automatically scroll. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { display.begin(); // Simple string display display.showString("Hi"); // Shows: Hi__ delay(1000); // 4-character string (fits display) display.showString("HELLO"); // Shows: HELL, then scrolls delay(2000); // Long string auto-scrolls display.showString("Hello World 1234"); delay(1000); // With position and length control // showString(string, length, position, dots) display.clear(); display.showString("AB", 2, 0); // Shows: AB__ (2 chars at position 0) delay(1000); // Degree symbol for temperature display display.showString("\xB0", 1, 3); // Degree mark at position 3 display.showNumber(72, false, 3, 0); // Temperature value at position 0 delay(1000); // Shows: _72* // Dynamic string with sprintf char buffer[10]; sprintf(buffer, "25%cC", '\xB0'); // "25°C" display.showString(buffer); delay(1000); // With colon/dots display.showString("HHSS", 4, 0, 0b01000000); // Shows: HH:SS } void loop() {} ``` -------------------------------- ### Handle User Interactions for TM1637 Display Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/examples/7-segment-animator.html Sets up event listeners for user interactions, including clicking on individual LED segments to toggle their state and clicking on the output section to load a specific frame. This enables interactive control of the display. ```javascript $(document).ready(function() { // Intercept LED mouse clicks and toggle LED $(".digit1 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit2 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit3 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit4 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); // Intercept mouse clicks in output section and load frame selected $( "#codeOutput" ).mousedown(function( event ) { var line = parseInt(event.offsetY/17); console.log("Line: "+ line); showFrame(line); }); }); updateValues(); ``` -------------------------------- ### TM1637TinyDisplay Library Methods Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/keywords.txt Overview of the primary methods available for controlling the TM1637 display hardware. ```APIDOC ## Library Methods ### Description Methods provided by the TM1637TinyDisplay and TM1637TinyDisplay6 classes to interact with the display. ### Methods - **begin()**: Initialize the display. - **setBrightness(level)**: Set the display brightness (use BRIGHT_LOW to BRIGHT_HIGH constants). - **setSegments(segments, length, pos)**: Manually set raw segment data. - **clear()**: Clear the display. - **showNumber(number)**: Display a numeric value. - **showNumberDec(number, leading_zero)**: Display a decimal number. - **showNumberHex(number)**: Display a hexadecimal number. - **showString(string)**: Display a string on the segments. - **showLevel(level)**: Display a level indicator. - **showAnimation(data, length, delay)**: Display a custom animation frame. - **flipDisplay(bool)**: Toggle display orientation. - **startAnimation(data, length, delay)**: Begin an animation sequence. - **startStringScroll(string, delay)**: Begin scrolling a string across the display. ``` -------------------------------- ### Display Strings with Dots Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/RELEASE.md Use showString to display text and control decimal points using a bitmask. ```cpp // void showString(const char s[], uint8_t length = MAXDIGITS, uint8_t pos = 0, uint8_t dots = 0); display.showString("HHSS",4,0,0b01000000); // Expect: HH:SS or HH.SS display.showString("1234",4,0,0b01000000); // Expect: 12:34 or 12.34 ``` -------------------------------- ### Control Display Brightness with setBrightness Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Sets the display brightness level (0-7) and optionally turns the display on or off. Supports predefined constants for brightness levels. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { display.begin(); display.showNumber(8888); // Cycle through brightness levels for (int level = 0; level <= 7; level++) { display.setBrightness(level); // 0 = dimmest, 7 = brightest delay(500); } // Use predefined constants display.setBrightness(BRIGHT_LOW); // Same as 0 delay(1000); display.setBrightness(BRIGHT_HIGH); // Same as 7 (0x0f) delay(1000); // Turn display off (retains data) display.setBrightness(7, false); // brightness, on/off delay(1000); // Turn display back on display.setBrightness(7, true); delay(1000); // Blinking effect for (int i = 0; i < 5; i++) { display.setBrightness(7, false); // Off delay(200); display.setBrightness(7, true); // On delay(200); } } void loop() {} ``` -------------------------------- ### Render Numbers and Handle Overflow Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/RELEASE.md Use showNumber to display integers or floats. Overflowing values will render as a dash display. ```cpp // Example of negative case that did not render correctly display.showNumber(-3.1, 1, 3, 1); // (float num, decimal length, length, position) // Overflow Examples - will render a dash display e.g. "----" display.showNumber(-1000); display.showNumber(10000000); display.showNumber(-333.1, 1, 3, 1); ``` -------------------------------- ### Display Animation Sequences with showAnimation Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Plays custom LED segment patterns defined in a 2D array. Use the FRAMES() macro to calculate frame counts and TIME_MS() for timing. ```cpp #include TM1637TinyDisplay display(4, 5); // Animation data - each row is a frame, each column is a digit // Segment bits: DP-G-F-E-D-C-B-A (bit 7 to bit 0) const uint8_t ANIMATION[12][4] = { { 0x08, 0x00, 0x00, 0x00 }, // Frame 0: bottom segment on digit 1 { 0x00, 0x08, 0x00, 0x00 }, // Frame 1: bottom segment on digit 2 { 0x00, 0x00, 0x08, 0x00 }, // Frame 2: bottom segment on digit 3 { 0x00, 0x00, 0x00, 0x08 }, // Frame 3: bottom segment on digit 4 { 0x00, 0x00, 0x00, 0x04 }, // Frame 4: bottom-right segment { 0x00, 0x00, 0x00, 0x02 }, // Frame 5: top-right segment { 0x00, 0x00, 0x00, 0x01 }, // Frame 6: top segment { 0x00, 0x00, 0x01, 0x00 }, // Frame 7: moving left { 0x00, 0x01, 0x00, 0x00 }, // Frame 8 { 0x01, 0x00, 0x00, 0x00 }, // Frame 9 { 0x20, 0x00, 0x00, 0x00 }, // Frame 10: top-left segment { 0x10, 0x00, 0x00, 0x00 } // Frame 11 }; void setup() { display.begin(); // Play animation // showAnimation(data, frames, delay_ms) // FRAMES() macro calculates frame count from array size // TIME_MS() macro for milliseconds, TIME_S() for seconds display.showAnimation(ANIMATION, FRAMES(ANIMATION), TIME_MS(50)); delay(1000); // Play multiple times for (int i = 0; i < 5; i++) { display.showAnimation(ANIMATION, 12, 100); // 12 frames, 100ms each } } void loop() {} ``` -------------------------------- ### Temperature Display with Special Characters Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Demonstrates combining numeric values with custom characters like the degree symbol using position control. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { display.begin(); } void loop() { // Display temperature with degree symbol // Position 3 shows degree mark, positions 0-2 show number display.showString("\xB0", 1, 3); // Degree symbol at position 3 // Simulate temperature readings for (int temp = -20; temp <= 120; temp++) { display.showNumber(temp, false, 3, 0); // 3 digits starting at position 0 delay(100); } delay(1000); // Alternative: show decimal temperature display.clear(); for (float temp = 20.0; temp <= 30.0; temp += 0.1) { display.showNumber(temp, 1, 4, 0); // 1 decimal place delay(100); } } ``` -------------------------------- ### Display Animation Sequence Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/README.md Call the showAnimation function with the animation data, number of frames, and timing to display the animation. ```cpp // Display Animation sequence display.showAnimation(ANIMATION, FRAMES(ANIMATION), TIME_MS(50)); ``` -------------------------------- ### Display Integer Numbers with TM1637TinyDisplay Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Displays integer numbers with options for leading zeros, fixed length, and position. Negative numbers are automatically handled with a minus sign. Use `showNumber(num, leading_zero, length, position)` for advanced control. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { display.begin(); // Basic integer display display.showNumber(1234); // Shows: 1234 delay(1000); // With leading zeros display.showNumber(42, true); // Shows: 0042 delay(1000); // Without leading zeros (default) display.showNumber(42, false); // Shows: __42 delay(1000); // Negative numbers display.showNumber(-99); // Shows: _-99 delay(1000); // Control length and position // showNumber(num, leading_zero, length, position) display.showNumber(14, false, 2, 1); // Shows: _14_ (2 digits at position 1) delay(1000); // Count from -100 to 100 for (int x = -100; x <= 100; x++) { display.showNumber(x); delay(50); } } void loop() {} ``` -------------------------------- ### Text to Clipboard Utility Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/examples/7-segment-animator.html Copies provided text content to the user's clipboard. It creates a temporary textarea element to perform the copy operation. ```javascript // Copy animation data to users clipboard function textToClipboard (text) { var dummy = document.createElement("textarea"); dummy.setAttribute('readonly', ''); dummy.style.position = 'absolute'; dummy.style.left = '-9999px'; document.body.appendChild(dummy); dummy.value = text; dummy.select(); document.execCommand("copy"); document.body.removeChild(dummy); } ``` -------------------------------- ### Display Level Indicator with showLevel Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Renders a percentage-based level meter on the display. Supports both horizontal and vertical orientations via the boolean parameter. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { display.begin(); // Horizontal level meter (left to right fill) for (int level = 0; level <= 100; level += 10) { display.showLevel(level, true); // true = horizontal delay(200); } // Vertical level meter (bottom to top fill) for (int level = 0; level <= 100; level += 10) { display.showLevel(level, false); // false = vertical delay(200); } // Animate level up and down for (int count = 0; count < 3; count++) { // Increase level for (int x = 0; x <= 100; x += 5) { display.showLevel(x, true); delay(20); } // Decrease level for (int x = 100; x >= 0; x -= 5) { display.showLevel(x, true); delay(20); } } } void loop() {} ``` -------------------------------- ### Display Floating Point Numbers Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/RELEASE.md Render floating point numbers by specifying decimal length, total length, and position. ```cpp // showNumber(num, decimal_length, length, pos) display.showNumber(9.87, 2, 3, 0); display.showNumber(1.23, 2, 3, 3); ``` -------------------------------- ### Manage Animation Data and UI Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/examples/7-segment-animator6.html Functions for handling animation frames, clipboard operations, and display state updates. ```javascript // Globals // var delayTime = 100; // Time between animation frames in ms var currentFrame = 0; // TODO - Allow editing of frames var HGFEDCBA = true; // Binary Map - True=HGFEDCBA and False=ABCDEFGH // Functions // // Popup to ask user msg to confirm function confirmErase(msg) { console.log("size: " + $('#codeOutput').text().length); if($('#codeOutput').text().length > 39) { return(window.confirm(msg)); } else return(true); } // Flip binary order to change mapping function flipByte(digitbin) { var ret = 0b00000000; console.log("digitbin: ".concat(digitbin," ret: ", ret)); if((digitbin & 0b00000001)>0) ret += 0b10000000; if((digitbin & 0b00000010)>0) ret += 0b01000000; if((digitbin & 0b00000100)>0) ret += 0b00100000; if((digitbin & 0b00001000)>0) ret += 0b00010000; if((digitbin & 0b00010000)>0) ret += 0b00001000; if((digitbin & 0b00100000)>0) ret += 0b00000100; if((digitbin & 0b01000000)>0) ret += 0b00000010; if((digitbin & 0b10000000)>0) ret += 0b00000001; return(ret); } // Toggle binary order for segment map function toggleMap() { if(HGFEDCBA) { HGFEDCBA = false; $('#map').text("ABCDEFGH"); } else { HGFEDCBA = true; $('#map').text("HGFEDCBA"); } formatData(true); updateValues(); } // Refresh button frame number indicator to last frame function updateFrame() { formatData(); var last = lastFrame(); showFrame(last); } // Toggle through speed options function updateSpeed() { switch(delayTime) { case 200: delayTime = 100; break; case 100: delayTime = 50; break; case 50: delayTime = 25; break; case 25: delayTime = 500; break; default: delayTime = 200; break; } $('#delay').text("Delay = ".concat(delayTime.toString())); } // Copy animation data to users clipboard function textToClipboard (text) { var dummy = document.createElement("textarea"); dummy.setAttribute('readonly', ''); dummy.style.position = 'absolute'; dummy.style.left = '-9999px'; document.body.appendChild(dummy); dummy.value = text; dummy.select(); document.execCommand("copy"); document.body.removeChild(dummy); } // Generate code from animation data and update code output div function copyCode() { formatData(); var frame = 0; var frameNum = lastFrame() + 1; var buffer = "/* Animation Data - "; if(HGFEDCBA) buffer = buffer + "HGFEDCBA Map */\n"; else buffer = buffer + "ABCDEFGH Map */\n"; buffer = buffer.concat("const uint8_t ANIMATION[",frameNum,"][6] = {"); // Copy data into code format and add to clipboard var lines = $('#codeOutput').text().split("\n"); while(frame < lines.length) { // Each frames to buffer var line = lines[frame]; if(frame == (lines.length-1)) { buffer = buffer.concat("\n ",line.replace("},","} ")); } else if(line.length > 19) { buffer = buffer.concat("\n ",line); } frame++; } buffer = buffer.concat("\n};"); console.log(buffer); textToClipboard(buffer); $('#codeOutput').text((buffer.concat(" ")).trim()); $("#outputblock").css("background-color","green"); } // Erase all animation data function clearData() { $('#codeOutput').text(''); $('#frame').text("Frame = 0"); $("#outputblock").css("background-color","salmon"); } // Load en example animation function exampleData() { var data = "{ 0x08, 0x00, 0x00, 0x00, 0x00, 0x00 },\n{ 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 },\n{ 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 },\n{ 0x00, 0x00, 0x00, 0x08, 0x00, 0x00 },\n{ 0x00, 0x00, 0x00, 0x00, 0x08, 0x00 },\n{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x08 },\n{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04 },\n{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },\n{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },\n{ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00 },\n{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 },\n{ 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 },\n{ 0x00, 0x01, 0x00, 0x00, 0x00, 0x00 },\n{ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00 },\n{ 0x20, 0x00, 0x00, 0x00, 0x00, 0x00 },\n{ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00 }"; $('#codeOutput').text(data); $("#outputblock").css("background-color","salmon"); formatData(!HGFEDCBA); } // Return the value of digit dig function grabValue(dig) { // Compute binary value based on segment LEDs var digitbin = 0; if($(dig.concat(" #a")).attr("class") == "on") digitbin += 0b00000001; if($(dig.concat(" #b")).attr("class") == "on") digitbin += 0b00000010; if($(dig.concat(" #c")).attr("class") == "on") digitbin += 0b00000100; if($(dig.concat(" #d")).attr("class") == "on") digitbin += 0b00001000; if($(dig.concat(" #e")).attr("class") == "on") digitbin += 0b00010000; if($(dig.concat(" #f")).attr("class") == "on") digitbin += 0b00100000; if($(dig.concat(" #g")).attr("class") == "on") digitbin += 0b01000000; if($(dig.concat(" #h")).attr("class") == "on") digitbin += 0b10000000; // Note: the svg LED segment values use HGFEDCBA map if(!HGFEDCBA) return(flipByte(digitbin)); // flip if ABCDEFGH map else return(digitbin); } // Clear all digits function clearDisplay(){ resetZero(".digit1"); resetZero(".digit2"); resetZero(".digit3"); resetZero(".digit4"); resetZero(".digit5"); resetZero(".digit6"); var frameNum = lastFrame() + 1; $('#frame').text("Frame = ".concat(frameNum.toSt ``` -------------------------------- ### UI Event Handling Source: https://github.com/jasonacox/tm1637tinydisplay/blob/master/examples/7-segment-animator6.html Event listeners for segment toggling and page navigation warnings. ```javascript $(window).bind('beforeunload', function(e){ if($('#codeOutput').text().length > 39) { return("Animation data will be lost - Proceed?"); } else e=null; }); ``` ```javascript $(document).ready(function() { $(".digit1 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit2 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit3 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit4 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit5 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $(".digit6 polygon").click(function() { var sSegClass = $(this).attr("class") === "off" ? "on" : "off"; $(this).attr("class", sSegClass); updateValues(); }); $( "#codeOutput" ).mousedown(function( event ) { var line = parseInt(event.offsetY/17); console.log("Line: "+ line); showFrame(line); }); }); ``` -------------------------------- ### Display Floating Point Numbers with TM1637TinyDisplay Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Displays floating-point numbers with automatic decimal point placement. The `decimal_length` parameter controls digits after the decimal. Requires displays with decimal point LEDs. Use `showNumber(num, decimal_length, length, position)` for advanced control. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { display.begin(); // Auto-format floating point display.showNumber(3.14); // Shows: 3.14 delay(1000); // Specify decimal places display.showNumber(1.234, 2); // Shows: 1.23 (2 decimal places) delay(1000); // Negative floating point display.showNumber(-1.5); // Shows: -1.5 delay(1000); // Zero prefix numbers display.showNumber(0.52); // Shows: 0.52 delay(1000); // With length and position control // showNumber(num, decimal_length, length, position) display.showNumber(9.87, 2, 3, 0); // Shows: 9.87 in positions 0-2 delay(1000); // Smooth counting with decimals for (int x = -100; x < 100; x++) { display.showNumber((float)x / 10.0); // -10.0 to 9.9 delay(50); } } void loop() {} ``` -------------------------------- ### Read Display Buffer Source: https://context7.com/jasonacox/tm1637tinydisplay/llms.txt Use readBuffer() to copy the current state of the display's internal buffer into a provided byte array. This is useful for backing up the current display content or for debugging. ```cpp #include TM1637TinyDisplay display(4, 5); void setup() { Serial.begin(9600); display.begin(); // Show something on display display.showNumber(1234); // Read current display buffer uint8_t buffer[4]; display.readBuffer(buffer); // Print segment values Serial.println("Current display buffer:"); for (int i = 0; i < 4; i++) { Serial.print("Digit "); Serial.print(i); Serial.print(": 0x"); Serial.println(buffer[i], HEX); } // Modify and restore display.showString("TEST"); delay(2000); // Restore previous display display.setSegments(buffer); } void loop() {} ```