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.

99 lines
2.5KB

  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <TFT_ILI9163C.h>
  4. // Color definitions
  5. #define BLACK 0x0000
  6. #define BLUE 0x001F
  7. #define RED 0xF800
  8. #define GREEN 0x07E0
  9. #define CYAN 0x07FF
  10. #define MAGENTA 0xF81F
  11. #define YELLOW 0xFFE0
  12. #define WHITE 0xFFFF
  13. const float sin_d[] = {
  14. 0,0.17,0.34,0.5,0.64,0.77,0.87,0.94,0.98,1,0.98,0.94,
  15. 0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,-0.5,-0.64,
  16. -0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,-0.77,
  17. -0.64,-0.5,-0.34,-0.17 };
  18. const float cos_d[] = {
  19. 1,0.98,0.94,0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,
  20. -0.5,-0.64,-0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,
  21. -0.77,-0.64,-0.5,-0.34,-0.17,0,0.17,0.34,0.5,0.64,0.77,
  22. 0.87,0.94,0.98};
  23. const float d = 10;
  24. float px[] = {
  25. -d, d, d, -d, -d, d, d, -d };
  26. float py[] = {
  27. -d, -d, d, d, -d, -d, d, d };
  28. float pz[] = {
  29. -d, -d, -d, -d, d, d, d, d };
  30. float p2x[] = {
  31. 0,0,0,0,0,0,0,0};
  32. float p2y[] = {
  33. 0,0,0,0,0,0,0,0};
  34. int r[] = {
  35. 0,0,0};
  36. /*
  37. Teensy3.x and Arduino's
  38. You are using 4 wire SPI here, so:
  39. MOSI: 11//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  40. MISO: 12//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  41. SCK: 13//Teensy3.x/Arduino UNO (for MEGA/DUE refere to arduino site)
  42. the rest of pin below:
  43. */
  44. #define __CS 10
  45. #define __DC 9
  46. /*
  47. Teensy 3.x can use: 2,6,9,10,15,20,21,22,23
  48. Arduino's 8 bit: any
  49. DUE: check arduino site
  50. If you do not use reset, tie it to +3V3
  51. */
  52. TFT_ILI9163C tft = TFT_ILI9163C(__CS, __DC);
  53. void setup() {
  54. tft.begin();
  55. }
  56. void loop(){
  57. tft.fillScreen(WHITE);
  58. r[0]=r[0]+1;
  59. r[1]=r[1]+1;
  60. if (r[0] == 36) r[0] = 0;
  61. if (r[1] == 36) r[1] = 0;
  62. if (r[2] == 36) r[2] = 0;
  63. for (int i=0;i<8;i++)
  64. {
  65. float px2 = px[i];
  66. float py2 = cos_d[r[0]]*py[i] - sin_d[r[0]]*pz[i];
  67. float pz2 = sin_d[r[0]]*py[i] + cos_d[r[0]]*pz[i];
  68. float px3 = cos_d[r[1]]*px2 + sin_d[r[1]]*pz2;
  69. float py3 = py2;
  70. float pz3 = -sin_d[r[1]]*px2 + cos_d[r[1]]*pz2;
  71. float ax = cos_d[r[2]]*px3 - sin_d[r[2]]*py3;
  72. float ay = sin_d[r[2]]*px3 + cos_d[r[2]]*py3;
  73. float az = pz3-190;
  74. p2x[i] = ((tft.width())/2)+ax*500/az;
  75. p2y[i] = ((tft.height())/2)+ay*500/az;
  76. }
  77. for (int i=0;i<3;i++) {
  78. tft.drawLine(p2x[i],p2y[i],p2x[i+1],p2y[i+1],BLACK);
  79. tft.drawLine(p2x[i+4],p2y[i+4],p2x[i+5],p2y[i+5],BLACK);
  80. tft.drawLine(p2x[i],p2y[i],p2x[i+4],p2y[i+4],BLACK);
  81. }
  82. tft.drawLine(p2x[3],p2y[3],p2x[0],p2y[0],BLACK);
  83. tft.drawLine(p2x[7],p2y[7],p2x[4],p2y[4],BLACK);
  84. tft.drawLine(p2x[3],p2y[3],p2x[7],p2y[7],BLACK);
  85. delay(15);
  86. }