这段代码的功能是通过 TM1637 驱动的七段显示器进行基本的显示操作。它包括初始化显示器、显示静态和动态信息、以及在主循环中进行数字计数和状态指示。
//TM1637驱动代码
#define LIGHTON LOW
#define LIGHTOFF HIGH
#include <Thread.h>
#define LED1 7
#define LED2 10
#define LED3 2
#define BAT A7
#define KEY1 PD3
#define KEY2 PD4
#define OUT1 PB0
#define OUT2 PB1
#define OUT3 PD6 //CLK
#define OUT4 PD5 //DIO
#define IN1 14
#define IN2 15
#define IN3 16
#define IN4 17
#include "SevenSegmentTM1637.h"
#define OFF 0
#define ON 1
const byte PIN_CLK = OUT3; // define CLK pin (any digital pin)
const byte PIN_DIO = OUT4; // define DIO pin (any digital pin)
SevenSegmentTM1637 display(PIN_CLK, PIN_DIO);
void setup() {
// initializes the Serial connection @ 9600 baud
display.begin(); // initializes the display
display.setBacklight(100); // set the brightness to 100 %
display.print("batt"); // display INIT on the display
delay(100); // wait 1000 ms
display.clear();
display.print(analogRead(A7)); // display INIT on the display
delay(500); // wait 1000 ms
display.clear();
};
// run loop (forever)
void loop() {
display.print("LOOP"); // display LOOP on the display
delay(1000); // wait 1000 ms
display.print("COUNTING SOME DIGITS");// print COUNTING SOME DIGITS
display.clear(); // clear the display
for (uint8_t i=0; i < 100; i++) { // loop from 0 to 100
display.print(i); // display loop counter
delay(100); // wait 100 ms
};
display.clear(); // clear the display
display.print("SUCC"); // print SUCC for success
display.blink(); // blink SUCC
delay(1000); // wait 1000 ms
};