PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

moodBackground.ino 1.0KB

3 år sedan
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. Modulate background color
  3. */
  4. #include <SPI.h>
  5. #include <RA8875.h>
  6. #define RA8875_RESET 9//any pin or nothing!
  7. #if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva
  8. RA8875 tft = RA8875(3);//select SPI module 3
  9. /*
  10. for module 3 (stellaris)
  11. SCLK: PD_0
  12. MOSI: PD_3
  13. MISO: PD_2
  14. SS: PD_1
  15. */
  16. #endif
  17. float angle;
  18. void setup()
  19. {
  20. tft.begin(RA8875_800x480);
  21. }
  22. // Translate a hue "angle" -120 to 120 degrees (ie -2PI/3 to 2PI/3) to
  23. // a 6-bit R channel value
  24. //
  25. // This is very slow on a microcontroller, not a great example!
  26. inline int angle_to_channel(float a) {
  27. if (a < -PI) a += 2 * PI;
  28. if (a < -2 * PI / 3 || a > 2 * PI / 3) return 0;
  29. float f_channel = cos(a * 3 / 4); // remap 120-degree 0-1.0 to 90 ??
  30. return ceil(f_channel * 255);//63
  31. }
  32. void loop() {
  33. 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);
  34. tft.fillWindow(clr);
  35. angle += 0.01;
  36. if (angle > PI)
  37. angle -= 2 * PI;
  38. }