special_panes.ino 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Lixie II "Special Panes" Example ////////////////////////////////////////////////////
  3. *
  4. * Lixie's 11th pane (which is a decimal point by default) can now be arbitrarily
  5. * controlled explicitly using the lix.special_pane() function and implicitly through
  6. * passing special Strings into lix.write();
  7. *
  8. * ----------------------------------------------------------------------------
  9. *
  10. * EXPLICIT CONTROL:
  11. * lix.special_pane(uint8_t index, bool enabled, [CRGB col1], [CRGB col2]);
  12. *
  13. * This function provides explicit control of the 11th panes, and the CRGB colors
  14. * passed to this function override any global color settings the displays currently
  15. * have. To show the rightmost digit's 11th pane in pure green:
  16. *
  17. * lix.special_pane(0, true, CRGB(0,255,0));
  18. *
  19. * You can optionally pass a second color to be used in a fashion similar
  20. * to lix.color_dual():
  21. *
  22. * lix.special_pane(0, true, CRGB(0,255,0), CRGB(0,0,255); // Green on left side, Blue on right
  23. *
  24. * These settings will persist indefinitely, until you disable that same pane:
  25. *
  26. * lix.special_pane(0, false);
  27. *
  28. * ----------------------------------------------------------------------------
  29. * IMPLICIT CONTROL:
  30. * lix.write(String input);
  31. *
  32. * When a String is passed to the lix.write(); function it will be parsed on a
  33. * character-by-character basis, where numerals behave as normal, spaces create
  34. * blank displays, and any other character is treated as a special pane character.
  35. *
  36. * For example, if you called lix.write("2.3 ");, the '.' is treated as an 11th pane
  37. * character, and the trailing space leaves your rightmost Lixie blank.
  38. *
  39. * This 11th pane behavior differs from explicit control in that it respects the
  40. * animation ISR and ON/OFF color groups that are already defined. This means that
  41. * they have normal transition-time behaviors and the 11th-pane chars will be colored
  42. * just as a normal numeral would at that position.
  43. *
  44. * To disable implicity controlled 11th panes once they are on, just write a different
  45. * value to the displays as you normally would.
  46. */
  47. #include <Lixie_II.h> // https://github.com/connornishijima/Lixie_II
  48. #define DATA_PIN 12 // Lixie DIN connects to this pin (D6 on Wemos)
  49. #define NUM_DIGITS 4
  50. Lixie_II lix(DATA_PIN, NUM_DIGITS);
  51. void setup() {
  52. lix.begin(); // Mandatory, sets up animation timer
  53. lix.gradient_rgb(ON, CRGB(255, 0, 0), CRGB(0, 255, 0)); // Gradient from red to green
  54. }
  55. void loop() {
  56. double_panes(); // EXPLICIT
  57. fake_load(); // IMPLICIT
  58. time_with_pm_dot(); // EXPLICIT
  59. delay(1000);
  60. }
  61. void double_panes() { // double_panes() uses special panes explicitly through lix.special_pane(uint8_t index, bool enabled, CRGB col1, CRGB col2);
  62. // and is independent of any lix.write() or lix.color_* animations
  63. lix.write(111111); // Writing a normal integer
  64. delay(1000);
  65. lix.write("222222"); // Passing in a string works as well
  66. delay(1000);
  67. lix.write("2222 2"); // spaces are treated as blank displays
  68. delay(1000);
  69. for (uint8_t i = 0; i < NUM_DIGITS; i++) { // enable special panes in green, one by one
  70. lix.special_pane(i, true, CRGB(0, 255, 0));
  71. delay(1000);
  72. }
  73. for (uint8_t i = 0; i < NUM_DIGITS; i++) { // enable dual-color special panes, one by one
  74. lix.special_pane(i, true, CRGB(0, 255, 255), CRGB(255, 0, 0));
  75. delay(1000);
  76. }
  77. for (uint8_t i = 0; i < NUM_DIGITS; i++) { // disable special panes, one by one
  78. lix.special_pane(i, false);
  79. delay(1000);
  80. }
  81. }
  82. void fake_load() { // fake_load() uses special panes implicitly through lix.write(String input); using spaces and periods, and respects the ON and OFF color groups
  83. // An example of implicitly enabling the special pane at index 2 (rightmost display is index 0) you could run: lix.write("3.14");
  84. for (uint8_t i = 0; i < 10; i++) { // repeats 10 times
  85. String message;
  86. for (uint8_t i = 0; i < NUM_DIGITS; i++) {
  87. message.concat(' ');
  88. }
  89. // Creates a "scanning" animation for any display size
  90. for (uint8_t x = 0; x < NUM_DIGITS; x++) {
  91. for (uint8_t y = 0; y < NUM_DIGITS; y++) {
  92. if (x == y) {
  93. message.setCharAt(y, '.');
  94. }
  95. else {
  96. message.setCharAt(y, ' ');
  97. }
  98. }
  99. // prints: ". ", then
  100. // " . ", then
  101. // " . ", then
  102. // " .", then loops
  103. lix.write(message);
  104. delay(250);
  105. }
  106. }
  107. }
  108. void time_with_pm_dot(){
  109. lix.write("1234"); // WRITE "TIME"
  110. // Blink "PM" dot on and off, in cyan, ten times
  111. for(uint8_t i = 0; i < 10; i++){
  112. lix.special_pane(3, true, CRGB(0, 255, 255));
  113. delay(1000);
  114. lix.special_pane(3, false);
  115. delay(1000);
  116. }
  117. }