Using Two More TM1637 4-Digit LED Displays with Arduino
This Arduino code makes it possible to connect two or more TM1637 4-digit seven-segment LED displays. Small (blue) and large black modules have both been tested and shown to work with the code below.
168-Using two more TM1637 4-digit LED displays
语言: C++
/*
* Original code from https://github.com/avishorp/TM1637
* Modified for Robojax video on October 28, 2018 at 15:05
* This is an Arduino sketch to use two or more TM1637 seven-segment LED displays
*
* Watch video instruction for this code:https://youtu.be/27KjMfPH1dk
*
* by Ahmad Shamshiri, in Ajax, Ontario, Canada
*
* display2.showNumberDec(23, true, 2,1);
* showNumberDec(arg1, arg2, arg3, arg4);
* arg1 is the number to be displayed
* arg2 can be 'true' or 'false' and if true it fills empty spots with data[]
* arg4 position of starting number on the display can be either 0, 1, 2 or 3
*/
#include <Arduino.h>
#include <TM1637Display.h>
// Module 1 connection pins (Digital Pins)
#define CLK1 5
#define DIO1 6
// Module 2 connection pins (Digital Pins)
#define CLK2 10
#define DIO2 11
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 5000
TM1637Display display1(CLK1, DIO1);// define display 1 object
TM1637Display display2(CLK2, DIO2);// define display 1 object
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 }; // all segments clear
void setup()
{
// Robojax.com two or more TM1637 Display 20181029
display1.setBrightness(0x0f);// set brightness of display 1
display2.setBrightness(0x0f);// set brightness of display 1
display1.setSegments(data);// fill display 1 with whatever data[] array has
display2.setSegments(data);// // fill display 2 with whatever data[] array has
// Robojax.com two or more TM1637 Display 20181029
}
void loop()
{
// Robojax.com two or more TM1637 Display 20181029
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,0);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,0);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,1);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,1);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,2);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,2);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data); // fill(clear) display with data[] array
display1.showNumberDec(23, false, 2,3);
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(34, false, 2,3);
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
/////////////////////////////////////////////////
display1.setSegments(data);// fill(clear) display with data[] array
display1.showNumberDec(741);// display 1
display2.setSegments(data);// fill(clear) display with data[] array
display2.showNumberDec(1562);// display 2
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
// Robojax.com two or more TM1637 Display 20181029
/////////////////////////////////////////////////
display1.setSegments(data);// fill(clear) display 1 with data[] array
display2.setSegments(data);// fill(clear) display 2 with data[] array
for(int i=0; i<=1273; i++)
{
display1.showNumberDec(i);// display from 0 to 1273 to display 1
display2.showNumberDec(i);// display from 0 to 1273 to display 2
}
delay(TEST_DELAY);// wait for TEST_DELAY milliseconds
// Robojax.com two or more TM1637 Display 20181029
}// loop end
资源与参考
尚无可用资源。
文件📁
没有可用的文件。