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.

44 lines
1.0KB

  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. // begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  13. tft.begin(RA8875_800x480);
  14. }
  15. // Translate a hue "angle" -120 to 120 degrees (ie -2PI/3 to 2PI/3) to
  16. // a 6-bit R channel value
  17. //
  18. // This is very slow on a microcontroller, not a great example!
  19. inline int angle_to_channel(float a) {
  20. if (a < -PI) a += 2 * PI;
  21. if (a < -2 * PI / 3 || a > 2 * PI / 3) return 0;
  22. float f_channel = cos(a * 3 / 4); // remap 120-degree 0-1.0 to 90 ??
  23. return ceil(f_channel * 255);//63
  24. }
  25. void loop() {
  26. 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);
  27. tft.fillWindow(clr);
  28. angle += 0.01;
  29. if (angle > PI)
  30. angle -= 2 * PI;
  31. }