TM1637Test.ino 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include <Arduino.h>
  2. #include <TM1637Display.h>
  3. // Module connection pins (Digital Pins)
  4. #define CLK 2
  5. #define DIO 3
  6. // The amount of time (in milliseconds) between tests
  7. #define TEST_DELAY 2000
  8. const uint8_t SEG_DONE[] = {
  9. SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
  10. SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
  11. SEG_C | SEG_E | SEG_G, // n
  12. SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
  13. };
  14. TM1637Display display(CLK, DIO);
  15. void setup()
  16. {
  17. }
  18. void loop()
  19. {
  20. int k;
  21. uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  22. display.setBrightness(0x0f);
  23. // All segments on
  24. display.setSegments(data);
  25. delay(TEST_DELAY);
  26. // Selectively set different digits
  27. data[0] = 0b01001001;
  28. data[1] = display.encodeDigit(1);
  29. data[2] = display.encodeDigit(2);
  30. data[3] = display.encodeDigit(3);
  31. for(k = 3; k >= 0; k--) {
  32. display.setSegments(data, 1, k);
  33. delay(TEST_DELAY);
  34. }
  35. display.setSegments(data+2, 2, 2);
  36. delay(TEST_DELAY);
  37. display.setSegments(data+2, 2, 1);
  38. delay(TEST_DELAY);
  39. display.setSegments(data+1, 3, 1);
  40. delay(TEST_DELAY);
  41. // Show decimal numbers with/without leading zeros
  42. bool lz = false;
  43. for (uint8_t z = 0; z < 2; z++) {
  44. for(k = 0; k < 10000; k += k*4 + 7) {
  45. display.showNumberDec(k, lz);
  46. delay(TEST_DELAY);
  47. }
  48. lz = true;
  49. }
  50. // Show decimal number whose length is smaller than 4
  51. for(k = 0; k < 4; k++)
  52. data[k] = 0;
  53. display.setSegments(data);
  54. // Run through all the dots
  55. for(k=0; k <= 4; k++) {
  56. display.showNumberDecEx(0, (0x80 >> k), true);
  57. delay(TEST_DELAY);
  58. }
  59. display.showNumberDec(153, false, 3, 1);
  60. delay(TEST_DELAY);
  61. display.showNumberDec(22, false, 2, 2);
  62. delay(TEST_DELAY);
  63. display.showNumberDec(0, true, 1, 3);
  64. delay(TEST_DELAY);
  65. display.showNumberDec(0, true, 1, 2);
  66. delay(TEST_DELAY);
  67. display.showNumberDec(0, true, 1, 1);
  68. delay(TEST_DELAY);
  69. display.showNumberDec(0, true, 1, 0);
  70. delay(TEST_DELAY);
  71. // Brightness Test
  72. for(k = 0; k < 4; k++)
  73. data[k] = 0xff;
  74. for(k = 0; k < 7; k++) {
  75. display.setBrightness(k);
  76. display.setSegments(data);
  77. delay(TEST_DELAY);
  78. }
  79. // On/Off test
  80. for(k = 0; k < 4; k++) {
  81. display.setBrightness(7, false); // Turn off
  82. display.setSegments(data);
  83. delay(TEST_DELAY);
  84. display.setBrightness(7, true); // Turn on
  85. display.setSegments(data);
  86. delay(TEST_DELAY);
  87. }
  88. // Done!
  89. display.setSegments(SEG_DONE);
  90. while(1);
  91. }