// TM1637 SevenSegment Counter Wokwi Example
//
// https://wokwi.com/projects/339227323398095442
#include <Arduino.h>
//#include <TM1637Display.h>
#include <TM1637TinyDisplay.h>
#include <DHT.h>
#define dataPin 4 //DHT
#define DHTTYPE DHT22
#define CLK 2 //数码管
#define DIO 3 //数码管
DHT dht(dataPin, DHTTYPE);
//bool showcelciusorfarenheit = false; //显示摄氏或华氏温度
//=====TM1637================================
//TM1637Display display(CLK, DIO);
TM1637TinyDisplay display(CLK, DIO);
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
};
// To save RAM space, we can store the animation sequences in PROGMEM read-only flash memory.
// This requires using the showAnimation_P() function to read from PROGMEM memory space.
const uint8_t ANIMATION2[40][4] PROGMEM = {
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 0
{ 0x01, 0x00, 0x00, 0x00 }, // Frame 1
{ 0x40, 0x01, 0x00, 0x00 }, // Frame 2
{ 0x08, 0x40, 0x00, 0x01 }, // Frame 3
{ 0x00, 0x08, 0x01, 0x40 }, // Frame 4
{ 0x01, 0x00, 0x40, 0x08 }, // Frame 5
{ 0x40, 0x01, 0x08, 0x00 }, // Frame 6
{ 0x08, 0x40, 0x00, 0x01 }, // Frame 7
{ 0x00, 0x08, 0x01, 0x40 }, // Frame 8
{ 0x01, 0x01, 0x40, 0x08 }, // Frame 9
{ 0x40, 0x40, 0x09, 0x00 }, // Frame 10
{ 0x08, 0x08, 0x40, 0x01 }, // Frame 11
{ 0x01, 0x00, 0x08, 0x40 }, // Frame 12
{ 0x40, 0x01, 0x00, 0x08 }, // Frame 13
{ 0x08, 0x40, 0x01, 0x00 }, // Frame 14
{ 0x01, 0x09, 0x41, 0x01 }, // Frame 15
{ 0x40, 0x40, 0x48, 0x40 }, // Frame 16
{ 0x08, 0x08, 0x08, 0x08 }, // Frame 17
{ 0x1c, 0x1c, 0x1c, 0x1c }, // Frame 18
{ 0x3e, 0x3e, 0x3e, 0x3e }, // Frame 19
{ 0xff, 0xff, 0xff, 0xff }, // Frame 20
{ 0xff, 0xff, 0xff, 0xff }, // Frame 21
{ 0xff, 0xff, 0xff, 0xff }, // Frame 22
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 23
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 24
{ 0xff, 0xff, 0xff, 0xff }, // Frame 25
{ 0xff, 0xff, 0xff, 0xff }, // Frame 26
{ 0xff, 0xff, 0xff, 0xff }, // Frame 27
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 28
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 29
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 30
{ 0xff, 0xff, 0xff, 0xff }, // Frame 31
{ 0xff, 0xff, 0xff, 0xff }, // Frame 32
{ 0xff, 0xff, 0xff, 0xff }, // Frame 33
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 34
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 35
{ 0x00, 0x00, 0x00, 0x00 }, // Frame 36
{ 0xff, 0xff, 0xff, 0xff }, // Frame 37
{ 0xff, 0xff, 0xff, 0xff }, // Frame 38
{ 0xff, 0xff, 0xff, 0xff } // Frame 39
};
const PROGMEM char FlashString2[] = "good";
//const uint8_t allON[] = {0xff, 0xff, 0xff, 0xff}; //88:88
//unsigned char WeiMa[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //位码
// unsigned char Digit[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0X90,0XBF,0X7F}; // (0-9),"-","."
const uint8_t a[] = {0x01,0x01,0x01,0x01};
const uint8_t b[] = {0x01 |0x02,0x01|0x02,0x01|0x02,0x01|0x02};
const uint8_t c[] = {0x01|0x02|0x04,0x01|0x02|0x04,0x01|0x02|0x04,0x01|0x02|0x04};
const uint8_t d[] = {0x01|0x02|0x04|0x08,0x01|0x02|0x04|0x08,0x01|0x02|0x04|0x08,0x01|0x02|0x04|0x08};
const uint8_t e[] = {0x01|0x02|0x04|0x08|0x10,0x01|0x02|0x04|0x08|0x10,0x01|0x02|0x04|0x08|0x10,0x01|0x02|0x04|0x08|0x10};
const uint8_t f[] = {0x01|0x02|0x04|0x08|0x10|0x20,0x01|0x02|0x04|0x08|0x10|0x20,0x01|0x02|0x04|0x08|0x10|0x20,0x01|0x02|0x04|0x08|0x10|0x20};
const uint8_t g[] = {0x01|0x02|0x04|0x08|0x10|0x20|0x40,0x01|0x02|0x04|0x08|0x10|0x20|0x40,0x01|0x02|0x04|0x08|0x10|0x20|0x40,0x01|0x02|0x04|0x08|0x10|0x20|0x40};
int8_t celsius[] = { // C
SEG_A | SEG_D | SEG_E | SEG_F //C 大写 0xC6
//SEG_D | SEG_E | SEG_G //c 小写 下 0xA7
// SEG_A | SEG_F | SEG_G // c 小写 上 0x9E
};
int8_t RH[] = { // RH
SEG_B | SEG_E | SEG_G //%
};
const uint8_t PASS[] = {
SEG_A | SEG_B | SEG_E | SEG_F | SEG_G, // P
SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G, // A
SEG_A | SEG_C | SEG_D | SEG_F | SEG_G, // S
SEG_A | SEG_C | SEG_D | SEG_F | SEG_G // S
};
#define TEST_DELAY 200
void setup() {
Serial.begin(9600);
delay(50);
display.begin();
display.setBrightness(3); //亮度
display.setSegments(a);
delay(TEST_DELAY);
display.setSegments(b);
delay(TEST_DELAY);
display.setSegments(c);
delay(TEST_DELAY);
display.setSegments(d);
delay(TEST_DELAY);
display.setSegments(e);
delay(TEST_DELAY);
display.setSegments(f);
delay(TEST_DELAY);
display.setSegments(g);
delay(TEST_DELAY);
display.showString_P(FlashString2);
delay(1000);
// Animation Sequence Test in SRAM - Run 3 times
display.clear();
for (int count = 0; count < 3; count++) {
display.showAnimation(ANIMATION, FRAMES(ANIMATION), TIME_MS(20));
}
display.clear();
delay(TEST_DELAY);
display.clear();
display.showAnimation_P(ANIMATION2, FRAMES(ANIMATION2), TIME_MS(80));
dht.begin();
}
void loop() {
float h = dht.readHumidity(); //湿度%
float t = dht.readTemperature(); //温度C
display.showString("\xB0", 1, 3); // Test with suffix
display.showNumber(t, 4, 3, 0);
delay(3000);
display.showNumber(h, 4, 3, 0);
//display.showString("0xd2",1,3);
display.setSegments(RH,1,3);
delay(3000);
for (int count = 0; count < 3; count++) {
display.showAnimation(ANIMATION, FRAMES(ANIMATION), TIME_MS(30));
}
delay(50);
//display.clear();
}