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.

simpletest.ino 1.8KB

3 vuotta sitten
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <Arduino.h>
  2. #include <SPI.h>
  3. #include <ssd1351.h>
  4. // use this to do Color c = RGB(...) instead of `RGB c = RGB(...)` or ssd1351::LowColor c = RGB(...)
  5. // because it's slightly faster and guarantees you won't be sending wrong colours to the display.
  6. // Choose color depth - IndexedColor, LowColor and HighColor currently supported
  7. // typedef ssd1351::IndexedColor Color;
  8. // typedef ssd1351::LowColor Color;
  9. typedef ssd1351::HighColor Color;
  10. // Choose display buffering - NoBuffer or SingleBuffer currently supported
  11. // auto display = ssd1351::SSD1351<Color, ssd1351::NoBuffer, 128, 96>();
  12. auto display = ssd1351::SSD1351<Color, ssd1351::SingleBuffer, 128, 96>();
  13. bool up = false;
  14. int pos = 127;
  15. const int particles = 256;
  16. int offsets[particles];
  17. int x_pos[particles];
  18. int y_pos[particles];
  19. Color particle_colors[particles];
  20. void setup() {
  21. Serial.begin(9600);
  22. Serial.println("Booting...");
  23. display.begin();
  24. Serial.println("Display set up.");
  25. for (int i = 0; i < particles; i++) {
  26. x_pos[i] = random(0, 128);
  27. y_pos[i] = random(0, 96);
  28. particle_colors[i] = ssd1351::RGB(0, i + 10, i/2 + 10);
  29. }
  30. }
  31. void loop() {
  32. unsigned long before = millis();
  33. display.fillScreen(ssd1351::RGB());
  34. Color circleColor = ssd1351::RGB(0, 128, 255);
  35. for (int i = 0; i < particles; i++) {
  36. offsets[i] += random(-2, 3);
  37. display.drawLine(
  38. x_pos[i] + offsets[i],
  39. y_pos[i] + offsets[i],
  40. pos,
  41. 80 + sin(pos / 4.0) * 20,
  42. particle_colors[i]
  43. );
  44. display.drawCircle(
  45. x_pos[i] + offsets[i],
  46. y_pos[i] + offsets[i],
  47. 1,
  48. circleColor
  49. );
  50. }
  51. display.updateScreen();
  52. Serial.println(millis() - before);
  53. if (up) {
  54. pos++;
  55. if (pos >= 127) {
  56. up = false;
  57. }
  58. } else {
  59. pos--;
  60. if (pos < 0) {
  61. up = true;
  62. }
  63. }
  64. }