• Adafruit_GFX matrix ws2812像素屏库使用教程AWTRIX2.0像素时钟


    AWTRIX2.0像素时钟很炫酷但必须要与服务器配合使用。这个库可以做自己的点阵时钟离线版。想怎么玩就怎么玩不受服务器牵绊。
    第一步:下载mixy库然后倒入,必须有以下库文件: Adafruit_GFX FastLED FastLED_NeoMatrix TomThumb
    #include //LDR光敏电阻
    #include
    #include
    #include
    #include //字体库
    特别说明TomThumb 字体必须用下载包里的字体,用原Adafruit_GFX字体效果很难看。
    在这里插入图片描述
    上测试时效果图:
    在这里插入图片描述
    需要的硬件:
    WS2812软点阵屏 32X8 256灯珠。
    在这里插入图片描述
    以上全部齐全后即可开整!先看库使用程序图。一看即懂。
    垂直线:
    在这里插入图片描述
    水平线
    在这里插入图片描述
    画空心矩形
    在这里插入图片描述
    显示效果
    在这里插入图片描述
    简单NTP时钟演示程序图
    在这里插入图片描述
    代码:

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    volatile int texiao;
    String lnnmonth;
    String lnnday;
    String huor;
    String feng;
    String seconds;
    volatile int ldrbr;
    int8_t timeZone = 8;
    const PROGMEM char *ntpServer = "ntp1.aliyun.com";
    volatile int item;
    
    LightDependentResistor myldr(A0,1000,LightDependentResistor::GL5516);
    
    CRGB leds[256];
    FastLED_NeoMatrix *matrix;
    void sysloop() {
      matrix->setTextColor(matrix->Color(0,200,160));
      matrix->setCursor(0,6);
      matrix->print(String(String(huor) + String(":")) + String(feng));
      matrix->setCursor(18,8);
      matrix->print(".......");
      matrix->setTextColor(matrix->Color(0,200,160));
      matrix->setCursor(25,6);
      matrix->print(lnnday);
      switch (NTP.getDateWeekday()) {
       case 1:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(18,8);
        matrix->print(".");
        matrix->show();
        break;
       case 2:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(20,8);
        matrix->print(".");
        matrix->show();
        break;
       case 3:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(22,8);
        matrix->print(".");
        matrix->show();
        break;
       case 4:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(24,8);
        matrix->print(".");
        matrix->show();
        break;
       case 5:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(26,8);
        matrix->print(".");
        matrix->show();
        break;
       case 6:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(28,8);
        matrix->print(".");
        matrix->show();
        break;
       case 7:
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor(30,8);
        matrix->print(".");
        matrix->show();
        break;
       default:
        break;
      }
      myfillRect(19, 1, 5, 5, matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));
      mydrawCircle(21, 3, 1, matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));
      for(int i = 2; i <= 12; i++)
      {
        matrix->setTextColor(matrix->Color((random(50, 255)),(random(50, 255)),(random(50, 255))));
        matrix->setCursor((i + 1),8);
        matrix->print(".");
        matrix->show();
        delay(500);
        if (i == 12) {
          texiao = texiao + 1;
          if (texiao >= 5) {
            texiao = 1;
    
          }
    
        }
      }
      Serial.println(NTP.getDateYear());
      item = random(1, 5);
      Serial.println(String("1=") + String(item));
      switch (item) {
       case 1:
        for(int j = -3; j<= 33; j++)
        {
          matrix->clear();
          mydrawFastVLine(j + 1, 0, 8, matrix->Color(0,200,160));
          delay(15);
        }
        break;
       case 2:
        for(int j = 32; j>-3; j--)
        {
          matrix->clear();
          mydrawFastVLine(j + 1, 0, 8, matrix->Color(0,200,160));
          delay(15);
        }
        break;
       case 3:
        for(int j = -3; j<=10; j++)
        {
          matrix->clear();
          mydrawFastHLine(0, j + 1, 32, matrix->Color(100,255,100));
          delay(30);
        }
        break;
       case 4:
        for(int j = 10; j>-3; j--)
        {
          matrix->clear();
          mydrawFastHLine(0, j + 1, 32, matrix->Color(100,255,100));
          delay(30);
        }
        break;
       default:
        break;
      }
      for(int j = 7; j<= 17; j++)
      {
        matrix->clear();
        matrix->setTextColor(matrix->Color(50,255,50));
        matrix->setCursor((j + 1),8);
        matrix->print(".");
        matrix->setTextColor(matrix->Color(50,50,200));
        matrix->setCursor(7,6);
        matrix->print(String(String(lnnmonth) + String("-")) + String(lnnday));
        matrix->show();
        delay(400);
      }
      item = random(1, 5);
      Serial.println(item);
      switch (item) {
       case 1:
        for(int j = -3; j<= 33; j++)
        {
          matrix->clear();
          mydrawFastVLine(j + 1, 0, 8, matrix->Color(0,200,160));
          delay(15);
        }
        break;
       case 2:
        for(int j = 32; j>-3; j--)
        {
          matrix->clear();
          mydrawFastVLine(j + 1, 0, 8, matrix->Color(0,200,160));
          delay(15);
        }
        break;
       case 3:
        for(int j = -3; j<=10; j++)
        {
          matrix->clear();
          mydrawFastHLine(0, j + 1, 32, matrix->Color(100,255,100));
          delay(30);
        }
        break;
       case 4:
        for(int j = 10; j>-3; j--)
        {
          matrix->clear();
          mydrawFastHLine(0, j + 1, 32, matrix->Color(100,255,100));
          delay(30);
        }
        break;
       default:
        break;
      }
    }
    
    void mydrawCircle(uint16_t x0, uint16_t y0, uint16_t r, uint16_t color) {
      matrix->drawCircle(x0,y0,r,color);
      matrix->show();
    }
    
    void mydrawFastHLine(int x, int y, int w, int color) {
      matrix->drawFastHLine(x,y,w,color);
      matrix->show();
    }
    
    void mydrawFastVLine(int x, int y, int h, int color) {
      matrix->drawFastVLine(x,y,h,color);
      matrix->show();
    }
    
    void myfillRect(int x, int y, int w, int h, int color) {
      matrix->fillRect(x,y,w,h,color);
      matrix->show();
    }
    
    void date_time() {
      if (NTP.getTimeHour24() >= 0 && NTP.getTimeHour24() <= 9) {
        huor = String("0") + String(NTP.getTimeHour24());
    
      } else {
        huor = NTP.getTimeHour24();
    
      }
      if (NTP.getTimeMinute() >= 0 && NTP.getTimeMinute() <= 9) {
        feng = String("0") + String(NTP.getTimeMinute());
    
      } else {
        feng = NTP.getTimeMinute();
    
      }
      if (NTP.getTimeSecond() >= 0 && NTP.getTimeSecond() <= 9) {
        seconds = String("0") + String(NTP.getTimeSecond());
    
      } else {
        seconds = NTP.getTimeSecond();
    
      }
      if (NTP.getDateMonth() >= 0 && NTP.getDateMonth() <= 9) {
        lnnmonth = String("0") + String(NTP.getDateMonth());
    
      } else {
        lnnmonth = NTP.getDateMonth();
    
      }
      if (NTP.getDateDay() >= 0 && NTP.getDateDay() <= 9) {
        lnnday = String("0") + String(NTP.getDateDay());
    
      } else {
        lnnday = NTP.getDateDay();
    
      }
    }
    
    void inithaed() {
      matrix->clear();
      matrix->setTextColor(matrix->Color((random(50, 250)),(random(50, 255)),(random(50, 250))));
      matrix->setCursor(5,6);
      matrix->print("MATRIX");
      matrix->show();
    }
    
    void setup(){
      texiao = 0;
      lnnmonth = "";
      lnnday = "";
      huor = "";
      feng = "";
      seconds = "";
      ldrbr = 0;
      Serial.begin(9600);
      myldr.setPhotocellPositionOnGround(false);
      WiFi.begin("Redmi_2.4G", "12345678");//Redmi_2.4G= 路由器ssid  12345678= 路由器密码。请改成你自己的ssid 密码
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
      }
    
      NTP.setInterval (600);
      NTP.setNTPTimeout (1500);
      NTP.begin (ntpServer, timeZone, false);
      matrix = new FastLED_NeoMatrix(leds, 32, 8, NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG);
      FastLED.addLeds<NEOPIXEL,4>(leds,256).setCorrection(TypicalLEDStrip);
      matrix->begin();
      matrix->setTextWrap(false);//显示字体
      matrix->setFont(&TomThumb);//字体
      matrix->setBrightness(5);
      inithaed();
      delay(2000);
      item = 0;
    }
    
    void loop(){
      //date_loop();
      date_time();
      randomSeed(millis());
      ldrbr = (map(myldr.getCurrentLux(), 0, 800, 5, 50));
      matrix->setBrightness(ldrbr);
      matrix->clear();
      sysloop();
      matrix->show();
      delay(50);
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296

    有问题或有需要改模块功能的 可留言

  • 相关阅读:
    使用光纤激光切割机等激光切割设备时的一些小诀窍
    2022牛客寒假算法基础集训营2
    美团外卖搜索基于Elasticsearch的优化实践
    我是如何写作的?
    Spring事件Event详解
    C++标准模板(STL)- 类型支持 (数值极限,traps,tinyness_before)
    面试经典150题——Day33
    vue 使用Html2Canvas对元素截图 下载
    奥特曼卡牌隐藏的百亿市场
    百度、阿里、腾讯、有道各平台翻译API申请教程
  • 原文地址:https://blog.csdn.net/lnwqh/article/details/127932267