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.

43 lines
917B

  1. /*
  2. Modulate background color
  3. */
  4. #include <SPI.h>
  5. #include <RA8875.h>
  6. #define RA8875_CS 10
  7. #define RA8875_RESET 9//any pin or nothing!
  8. RA8875 tft = RA8875(RA8875_CS, RA8875_RESET);
  9. float angle;
  10. void setup()
  11. {
  12. tft.begin(RA8875_800x480);
  13. }
  14. // Translate a hue "angle" -120 to 120 degrees (ie -2PI/3 to 2PI/3) to
  15. // a 6-bit R channel value
  16. //
  17. // This is very slow on a microcontroller, not a great example!
  18. inline int angle_to_channel(float a) {
  19. if (a < -PI) a += 2 * PI;
  20. if (a < -2 * PI / 3 || a > 2 * PI / 3) return 0;
  21. float f_channel = cos(a * 3 / 4); // remap 120-degree 0-1.0 to 90 ??
  22. return ceil(f_channel * 255);//63
  23. }
  24. void loop() {
  25. uint16_t clr = (((angle_to_channel(angle - 4 * PI / 3) >> 1) & 0xF8) << 8) | (((angle_to_channel(angle - 2 * PI / 3)) & 0xFC) << 3) | ((angle_to_channel(angle) >> 1) >> 3);
  26. tft.fillWindow(clr);
  27. angle += 0.01;
  28. if (angle > PI)
  29. angle -= 2 * PI;
  30. }