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.

64 lines
1.9KB

  1. /*
  2. Setting grayscale from progmem to save RAM. If you want to play
  3. multiple "frames", (an animation), see the BasicAnimations Example.
  4. See the BasicUse example for hardware setup.
  5. Alex Leone <acleone ~AT~ gmail.com>, 2009-02-03 */
  6. #include "Tlc5940.h"
  7. // Extended functions (they start with tlc_...) require another include
  8. #include "tlc_progmem_utils.h"
  9. /*
  10. This is an array in program memory. Program memory is 16kB instead of
  11. 1024 bytes for regular variables in SRAM.
  12. The format for this array is
  13. GS_DUO(OUT15, OUT14), ... GS_DUO(OUT1, OUT0)
  14. If you have more than one TLC, the format is
  15. GS_DUO(TLC2.OUT15, TLC2.OUT14), ... GS_DUO(TLC2.OUT1, TLC2.OUT0),
  16. GS_DUO(TLC1.OUT15, TLC1.OUT14), ... GS_DUO(TLC1.OUT1, TLC1.OUT0)
  17. The pattern below will only work with 1 TLC. Copy + Paste the 4 lines
  18. inside the curly brackets for each additional TLC. */
  19. const unsigned int TlcMax = 4095;
  20. const uint8_t gsArray1[NUM_TLCS * 24] PROGMEM = {
  21. GS_DUO((TlcMax * 16)/16, (TlcMax * 15)/16), GS_DUO((TlcMax * 14)/16, (TlcMax * 13)/16),
  22. GS_DUO((TlcMax * 12)/16, (TlcMax * 11)/16), GS_DUO((TlcMax * 10)/16, (TlcMax * 9)/16),
  23. GS_DUO((TlcMax * 8)/16, (TlcMax * 7)/16), GS_DUO((TlcMax * 6)/16, (TlcMax * 5)/16),
  24. GS_DUO((TlcMax * 4)/16, (TlcMax * 3)/16), GS_DUO((TlcMax * 2)/16, (TlcMax * 1)/16),
  25. };
  26. void setup()
  27. {
  28. Tlc.init();
  29. }
  30. void loop()
  31. {
  32. // Display the pattern (brightness ramp over the outputs)
  33. tlc_setGSfromProgmem(gsArray1);
  34. Tlc.update();
  35. // Fade each channel to zero
  36. for (TLC_CHANNEL_TYPE channel = 0; channel < NUM_TLCS * 16; channel++) {
  37. int16_t initialValue = Tlc.get(channel);
  38. while (initialValue > 0) {
  39. initialValue -= 5;
  40. if (initialValue < 0) {
  41. initialValue = 0;
  42. }
  43. Tlc.set(channel, initialValue);
  44. // wait until the data has been sent to the TLCs before continuing
  45. while (Tlc.update());
  46. }
  47. }
  48. }