PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.1KB

  1. /*
  2. Basic Pin setup:
  3. ------------ ---u----
  4. ARDUINO 13|-> SCLK (pin 25) OUT1 |1 28| OUT channel 0
  5. 12| OUT2 |2 27|-> GND (VPRG)
  6. 11|-> SIN (pin 26) OUT3 |3 26|-> SIN (pin 11)
  7. 10|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 13)
  8. 9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
  9. 8| . |6 23|-> BLANK (pin 10)
  10. 7| . |7 22|-> GND
  11. 6| . |8 21|-> VCC (+5V)
  12. 5| . |9 20|-> 2K Resistor -> GND
  13. 4| . |10 19|-> +5V (DCPRG)
  14. 3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3)
  15. 2| . |12 17|-> SOUT
  16. 1| . |13 16|-> XERR
  17. 0| OUT14|14 15| OUT channel 15
  18. ------------ --------
  19. - Put the longer leg (anode) of the LEDs in the +5V and the shorter leg
  20. (cathode) in OUT(0-15).
  21. - +5V from Arduino -> TLC pin 21 and 19 (VCC and DCPRG)
  22. - GND from Arduino -> TLC pin 22 and 27 (GND and VPRG)
  23. - digital 3 -> TLC pin 18 (GSCLK)
  24. - digital 9 -> TLC pin 24 (XLAT)
  25. - digital 10 -> TLC pin 23 (BLANK)
  26. - digital 11 -> TLC pin 26 (SIN)
  27. - digital 13 -> TLC pin 25 (SCLK)
  28. - The 2K resistor between TLC pin 20 and GND will let ~20mA through each
  29. LED. To be precise, it's I = 39.06 / R (in ohms). This doesn't depend
  30. on the LED driving voltage.
  31. - (Optional): put a pull-up resistor (~10k) between +5V and BLANK so that
  32. all the LEDs will turn off when the Arduino is reset.
  33. If you are daisy-chaining more than one TLC, connect the SOUT of the first
  34. TLC to the SIN of the next. All the other pins should just be connected
  35. together:
  36. BLANK on Arduino -> BLANK of TLC1 -> BLANK of TLC2 -> ...
  37. XLAT on Arduino -> XLAT of TLC1 -> XLAT of TLC2 -> ...
  38. The one exception is that each TLC needs it's own resistor between pin 20
  39. and GND.
  40. This library uses the PWM output ability of digital pins 3, 9, 10, and 11.
  41. Do not use analogWrite(...) on these pins.
  42. This sketch does the Knight Rider strobe across a line of LEDs.
  43. Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
  44. #include "Tlc5940.h"
  45. void setup()
  46. {
  47. /* Call Tlc.init() to setup the tlc.
  48. You can optionally pass an initial PWM value (0 - 4095) for all channels.*/
  49. Tlc.init();
  50. }
  51. /* This loop will create a Knight Rider-like effect if you have LEDs plugged
  52. into all the TLC outputs. NUM_TLCS is defined in "tlc_config.h" in the
  53. library folder. After editing tlc_config.h for your setup, delete the
  54. Tlc5940.o file to save the changes. */
  55. void loop()
  56. {
  57. int direction = 1;
  58. for (int channel = 0; channel < NUM_TLCS * 16; channel += direction) {
  59. /* Tlc.clear() sets all the grayscale values to zero, but does not send
  60. them to the TLCs. To actually send the data, call Tlc.update() */
  61. Tlc.clear();
  62. /* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for
  63. one channel (15 is OUT15 on the first TLC, if multiple TLCs are daisy-
  64. chained, then channel = 16 would be OUT0 of the second TLC, etc.).
  65. value goes from off (0) to always on (4095).
  66. Like Tlc.clear(), this function only sets up the data, Tlc.update()
  67. will send the data. */
  68. if (channel == 0) {
  69. direction = 1;
  70. } else {
  71. Tlc.set(channel - 1, 1000);
  72. }
  73. Tlc.set(channel, 4095);
  74. if (channel != NUM_TLCS * 16 - 1) {
  75. Tlc.set(channel + 1, 1000);
  76. } else {
  77. direction = -1;
  78. }
  79. /* Tlc.update() sends the data to the TLCs. This is when the LEDs will
  80. actually change. */
  81. Tlc.update();
  82. delay(75);
  83. }
  84. }