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.

62 lines
1.5KB

  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <TFT_ILI9163C.h>
  4. #define BLACK 0x0000
  5. #define BLUE 0x001F
  6. #define RED 0xF800
  7. #define GREEN 0x07E0
  8. #define CYAN 0x07FF
  9. #define MAGENTA 0xF81F
  10. #define YELLOW 0xFFE0
  11. #define WHITE 0xFFFF
  12. #define TRANSPARENT -1
  13. /*
  14. Teensy3.x and Arduino's
  15. You are using 4 wire SPI here, so:
  16. MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  17. MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  18. SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  19. the rest of pin below:
  20. */
  21. #define __CS 10
  22. #define __DC 9
  23. /*
  24. Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
  25. Arduino's 8 bit: any
  26. DUE: check arduino site
  27. If you do not use reset, tie it to +3V3
  28. */
  29. TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
  30. float angle;
  31. void setup()
  32. {
  33. tft.begin();
  34. }
  35. // Translate a hue "angle" -120 to 120 degrees (ie -2PI/3 to 2PI/3) to
  36. // a 6-bit R channel value
  37. //
  38. // This is very slow on a microcontroller, not a great example!
  39. inline int angle_to_channel(float a) {
  40. if (a < -PI) a += 2*PI;
  41. if (a < -2*PI/3 || a > 2*PI/3) return 0;
  42. float f_channel = cos(a*3/4); // remap 120-degree 0-1.0 to 90 ??
  43. return ceil(f_channel * 255);//63
  44. }
  45. void loop() {
  46. 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);
  47. tft.fillScreen(clr);
  48. angle += 0.01;
  49. if(angle > PI)
  50. angle -= 2*PI;
  51. }