|
本帖最后由 vip2128 于 2024-8-16 09:08 编辑
又搞了一块电动车显示屏,ic是TM1640,2线驱动,不同于前改TM1629A的3线驱动
--------------------------
arduino代码如下
- #include <ESP8266WiFi.h>
- #define NTP1 "ntp2.aliyun.com"
- #define NTP2 "ntp1.aliyun.com"
- #define NTP3 "ntp3.aliyun.com"
- struct tm timeinfo;
- const char* ssid = "abc"; //改SSID
- const char* password = "abc"; //改password
- const size_t MaxString = 15;
- char oldTimeString[MaxString] = { 0 };
- char newTimeString[MaxString] = { 0 };
- char oldTimeString1[MaxString] = { 0 };
- char newTimeString1[MaxString] = { 0 };
- byte tm_buffer[16] = { 0x00 };
- int tm_wday, ww, hour, minute, second;
- const unsigned char tm_digit[13] = {
- 0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, // 0-4
- 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111, // 5-9
- 0b0001001, // 10 test
- 0b0000000, // 11 test
- 0b0000001 // 12 灯 or M
- };
- int tm_dio = D6; // D6 nodemcu ESP8266 // 1 tx esp01-s
- int tm_clk = D7; // D7 // 3 rx
- void setup() {
- Serial.begin(115200);
- startSTA();
- setClock();
- init(4); //0-7 亮度
- }
- void loop() {
- setClock();
- int sec_ge = second % 10;
- int sec_shi = second / 10;
- int hour_ge = hour % 10;
- int hour_shi = hour / 10;
- int min_ge = minute % 10;
- int min_shi = minute / 10;
- TM1640_start();
- tm_sendByte(0xc0);
- tm_sendByte(tm_digit[sec_shi]); //秒十
- tm_sendByte(tm_digit[sec_shi]); //秒十
- tm_sendByte(tm_digit[sec_ge]); //秒个
- tm_sendByte(tm_digit[sec_ge]); //秒个
- tm_sendByte(tm_digit[hour_shi]); //时十
- tm_sendByte(tm_digit[hour_ge]); //时个
- tm_sendByte(tm_digit[min_shi]); //分十
- tm_sendByte(tm_digit[min_ge]); //分个
- tm_sendByte(tm_digit[ww]); //星期
- tm_sendByte(tm_digit[12); //灯
- tm_sendByte(tm_digit[12); // M
- TM1640_end();
- }
- void tm_sendByte(byte data) {
- for (int i = 0; i < 8; i++) {
- digitalWrite(tm_clk, LOW);
- digitalWrite(tm_dio, data & 1 ? HIGH : LOW);
- data >>= 1;
- digitalWrite(tm_clk, HIGH);
- bitDelay();
- }
- bitDelay();
- }
- void init(int intensity) {
- pinMode(tm_dio, OUTPUT);
- pinMode(tm_clk, OUTPUT);
- TM1640_start();
- setIntensity(intensity);
- for (int i = 0; i < 16; i++) { tm_sendByte(0x0); } // 0x0清零 全亮7f abcdefg
- TM1640_end();
- }
- void setIntensity(int intensity) {
- if (intensity < 0) {
- tm_sendByte(0x80);
- return;
- }
- tm_sendByte(0x88 | (intensity % 8));
- }
- void TM1640_start() {
- digitalWrite(tm_clk, HIGH);
- digitalWrite(tm_dio, HIGH);
- digitalWrite(tm_dio, LOW);
- digitalWrite(tm_clk, LOW);
- }
- void TM1640_end() {
- digitalWrite(tm_dio, LOW);
- digitalWrite(tm_clk, HIGH);
- digitalWrite(tm_dio, HIGH);
- }
- void bitDelay() {
- #if F_CPU > 100000000
- delayMicroseconds(1);
- #endif
- }
- void startSTA() {
- WiFi.disconnect();
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- }
- Serial.println("WiFi connected");
- }
- void setClock() {
- if (!getLocalTime(&timeinfo)) {
- configTime(8 * 3600, 0, NTP1, NTP2, NTP3);
- return;
- }
- sprintf(
- newTimeString,
- "%d",
- timeinfo.tm_min);
- if (strcmp(newTimeString, oldTimeString) != 0) {
- ww = timeinfo.tm_wday;
- if (ww == 0) ww = 8;
- hour = timeinfo.tm_hour;
- minute = timeinfo.tm_min;
- strcpy(oldTimeString, newTimeString);
- }
- sprintf(
- newTimeString1,
- "%d",
- timeinfo.tm_sec);
- if (strcmp(newTimeString1, oldTimeString1) != 0) {
- second = timeinfo.tm_sec;
- Serial.println(second);
- strcpy(oldTimeString1, newTimeString1);
- if (minute == 0 && second == 0) // 整点预报
- {
- //
- }
- }
- }
再改电动车TM1629A显示屏 附ESP01-s wifi时钟arduino代码
https://www.mydigit.cn/forum.php?mod=viewthread&tid=464177&fromuid=768940
ESP8266改造电动车显示屏为 WIFI语音报时时钟
https://www.mydigit.cn/forum.php?mod=viewthread&tid=459652&fromuid=768940
电动车显示屏TM1629A共阳极改wifi时钟arduino代码
https://www.mydigit.cn/forum.php?mod=viewthread&tid=461725&fromuid=768940
自制超小可更新语音模块
https://www.mydigit.cn/forum.php?mod=viewthread&tid=466530&fromuid=768940
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
打赏
-
查看全部打赏
|