查看: 3457|回复: 0

【Tiny ML微型机器学习开发板】流星显示背景效果

[复制链接]
  • TA的每日心情

    2021-7-15 14:11
  • 签到天数: 4 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2021-7-15 14:24:20 | 显示全部楼层 |阅读模式
    分享到:


    通过开发板所带的例程,我们能够测试LCD的显示效果
    IMG_20210710_083532.jpg 程序代码:
    1. // Animates white pixels to simulate flying through a star field

    2. #include <SPI.h>
    3. #include <TFT_eSPI.h>

    4. // Use hardware SPI
    5. TFT_eSPI tft = TFT_eSPI();

    6. // With 1024 stars the update rate is ~65 frames per second
    7. #define NSTARS 1024
    8. uint8_t sx[NSTARS] = {};
    9. uint8_t sy[NSTARS] = {};
    10. uint8_t sz[NSTARS] = {};

    11. uint8_t za, zb, zc, zx;

    12. // Fast 0-255 random number generator from http://eternityforest.com/Projects/rng.php:
    13. uint8_t __attribute__((always_inline)) rng() {
    14.     zx++;
    15.     za = (za ^ zc ^ zx);
    16.     zb = (zb + za);
    17.     zc = (zc + (zb >> 1)^za);
    18.     return zc;
    19. }

    20. void setup() {
    21.     za = random(256);
    22.     zb = random(256);
    23.     zc = random(256);
    24.     zx = random(256);

    25.     Serial.begin(115200);
    26.     tft.init();
    27.     tft.setRotation(1);
    28.     tft.fillScreen(TFT_BLACK);

    29.     // fastSetup() must be used immediately before fastPixel() to prepare screen
    30.     // It must be called after any other graphics drawing function call if fastPixel()
    31.     // is to be called again
    32.     //tft.fastSetup(); // Prepare plot window range for fast pixel plotting
    33. }

    34. void loop() {
    35.     unsigned long t0 = micros();
    36.     uint8_t spawnDepthVariation = 255;

    37.     for (int i = 0; i < NSTARS; ++i) {
    38.         if (sz[i] <= 1) {
    39.             sx[i] = 160 - 120 + rng();
    40.             sy[i] = rng();
    41.             sz[i] = spawnDepthVariation--;
    42.         } else {
    43.             int old_screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160;
    44.             int old_screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120;

    45.             // This is a faster pixel drawing function for occassions where many single pixels must be drawn
    46.             tft.drawPixel(old_screen_x, old_screen_y, TFT_BLACK);

    47.             sz[i] -= 2;
    48.             if (sz[i] > 1) {
    49.                 int screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160;
    50.                 int screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120;

    51.                 if (screen_x >= 0 && screen_y >= 0 && screen_x < 320 && screen_y < 240) {
    52.                     uint8_t r, g, b;
    53.                     r = g = b = 255 - sz[i];
    54.                     tft.drawPixel(screen_x, screen_y, tft.color565(r, g, b));
    55.                 } else {
    56.                     sz[i] = 0;    // Out of screen, die.
    57.                 }
    58.             }
    59.         }
    60.     }
    61.     unsigned long t1 = micros();
    62.     //static char timeMicros[8] = {};

    63.     // Calcualte frames per second
    64.     Serial.println(1.0 / ((t1 - t0) / 1000000.0));
    65. }

    复制代码

    LCD显示效果:
    流星效果动态显示
    IMG_20210710_083509.jpg

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-11-19 12:42 , Processed in 0.107656 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.