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.

108 lines
2.5KB

  1. /* A 3d rotating cube
  2. Tested and worked with:
  3. Stellaris
  4. Works with Energia 0013 IDE
  5. */
  6. #include <SPI.h>
  7. #include <RA8875.h>
  8. #define RA8875_RESET 9//any pin or nothing!
  9. #if defined(NEEDS_SET_MODULE)//Energia, this case is for stellaris/tiva
  10. RA8875 tft = RA8875(3);//select SPI module 3
  11. /*
  12. for module 3 (stellaris)
  13. SCLK: PD_0
  14. MOSI: PD_3
  15. MISO: PD_2
  16. SS: PD_1
  17. */
  18. #endif
  19. float sin_d[] = {
  20. 0,0.17,0.34,0.5,0.64,0.77,0.87,0.94,0.98,1,0.98,0.94,
  21. 0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,-0.5,-0.64,
  22. -0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,-0.77,
  23. -0.64,-0.5,-0.34,-0.17 };
  24. float cos_d[] = {
  25. 1,0.98,0.94,0.87,0.77,0.64,0.5,0.34,0.17,0,-0.17,-0.34,
  26. -0.5,-0.64,-0.77,-0.87,-0.94,-0.98,-1,-0.98,-0.94,-0.87,
  27. -0.77,-0.64,-0.5,-0.34,-0.17,0,0.17,0.34,0.5,0.64,0.77,
  28. 0.87,0.94,0.98};
  29. float d = 30;
  30. float px[] = {
  31. -d, d, d, -d, -d, d, d, -d };
  32. float py[] = {
  33. -d, -d, d, d, -d, -d, d, d };
  34. float pz[] = {
  35. -d, -d, -d, -d, d, d, d, d };
  36. float p2x[] = {
  37. 0,0,0,0,0,0,0,0};
  38. float p2y[] = {
  39. 0,0,0,0,0,0,0,0};
  40. int r[] = {
  41. 0,0,0};
  42. void setup() {
  43. Serial.begin(9600);
  44. Serial.println("RA8875 start");
  45. tft.begin(RA8875_480x272);
  46. }
  47. uint16_t ccolor = RA8875_GREEN;
  48. uint8_t ch = 0;
  49. void loop() {
  50. tft.fillWindow();
  51. r[0] = r[0] + 1;
  52. r[1] = r[1] + 1;
  53. if (r[0] == 36) r[0] = 0;
  54. if (r[1] == 36) r[1] = 0;
  55. if (r[2] == 36) r[2] = 0;
  56. for (int i = 0; i < 8; i++)
  57. {
  58. float px2 = px[i];
  59. float py2 = cos_d[r[0]] * py[i] - sin_d[r[0]] * pz[i];
  60. float pz2 = sin_d[r[0]] * py[i] + cos_d[r[0]] * pz[i];
  61. float px3 = cos_d[r[1]] * px2 + sin_d[r[1]] * pz2;
  62. float py3 = py2;
  63. float pz3 = -sin_d[r[1]] * px2 + cos_d[r[1]] * pz2;
  64. float ax = cos_d[r[2]] * px3 - sin_d[r[2]] * py3;
  65. float ay = sin_d[r[2]] * px3 + cos_d[r[2]] * py3;
  66. float az = pz3 - 190;
  67. p2x[i] = ((tft.width()) / 2) + ax * 500 / az;
  68. p2y[i] = ((tft.height()) / 2) + ay * 500 / az;
  69. }
  70. for (int i = 0; i < 3; i++) {
  71. tft.drawLine(p2x[i], p2y[i], p2x[i + 1], p2y[i + 1], ccolor);
  72. tft.drawLine(p2x[i + 4], p2y[i + 4], p2x[i + 5], p2y[i + 5], ccolor);
  73. tft.drawLine(p2x[i], p2y[i], p2x[i + 4], p2y[i + 4], ccolor);
  74. }
  75. tft.drawLine(p2x[3], p2y[3], p2x[0], p2y[0], ccolor);
  76. tft.drawLine(p2x[7], p2y[7], p2x[4], p2y[4], ccolor);
  77. tft.drawLine(p2x[3], p2y[3], p2x[7], p2y[7], ccolor);
  78. #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__) || defined(__SAM3X8E__)
  79. delay(40);
  80. #else
  81. delay(10);
  82. #endif
  83. if (ch >= 20) {
  84. ch = 0;
  85. ccolor = random(RA8875_BLUE, RA8875_WHITE);
  86. }
  87. else {
  88. ch++;
  89. }
  90. }