#include <TM1637Display.h>
// Pins for 4-digit 7-segment display:
#define CLK 6
#define DIO 5
// Create an object of type TM1637Display, representing the display:
TM1637Display display = TM1637Display(CLK, DIO);
// Array which sets all segments to on:
const uint8_t all_on[] = {0xff, 0xff, 0xff, 0xff};
// each entry above is 1111111 (in binary), i.e. 255 (base 10) in hexadecimal.
// Array which sets all segments to off:
const uint8_t blank[] = {0x00, 0x00, 0x00, 0x00};
// Can set individual segments to spell digits, words, or create other symbols
// by performing bitwise OR operations of the segments you need to turn on:
const uint8_t done[] = {
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // o
SEG_C | SEG_E | SEG_G, // n
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // e
};
int i = 0; // loop counter
void setup() {
// put your setup code here, to run once:
// Initialize 4-digit 7-segment display:
display.clear();
delay(1000);
// Set the brightness:
display.setBrightness(7);
// Turn all segments on:
display.setSegments(all_on);
delay(2000);
display.clear();
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
// Demonstration of displaying base-10 numbers on display:
display.showNumberDec(i);
delay(1000);
// End counter, when it reaches 123:
if (i>=123) {
delay(2000);
display.clear();
delay(1000);
display.setSegments(done);
while(1); // hang here forever.
}
i = i+1; // increment loop counter.
}