• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

项目1多功能墨水屏新闻、天气台历二

武飞扬头像
喜暖知寒
帮助2


目录

NTP.h

定义

initNTP():Login to WiFi network and assign the time sync provider

getNTPTime():NTP Time Provider Code

sendNTPpacket():Send an NTP request to the time server at the given address

get_weather()、updatetime()、hitokoto()、newsdisplay()、gettem()

get_weather()

updatetime()

hitokoto()一言

newsdisplay()新闻

gettem()温湿度


开始看loop()函数中的第二步,initNTP()函数,定义在NTP.h文件中。

NTP.h

定义

  1.  
    #include <Arduino.h>
  2.  
    #include <TimeLib.h>
  3.  
    #include <WiFiUdp.h>
  4.  
     
  5.  
    #define LOCALPORT 5000 // Local port to listen for UDP packets
  6.  
    #define NTP_PACKET_SIZE 48 // NTP time stamp is in the first 48 bytes of the message
  7.  
     
  8.  
    // A UDP instance to let us send and receive packets over UDP
  9.  
    WiFiUDP udp;
  10.  
     
  11.  
    byte packetBuffer[NTP_PACKET_SIZE]; // Buffer to hold incoming and outgoing packets
  12.  
     
  13.  
    // Don't hardwire the IP address or we won't get the benefits of the time server pool.
  14.  
    const char *ntpServerName ;//= "time.windows.com";//"1.cn.pool.ntp.org";
  15.  
    IPAddress timeServerIP(120,25,108,11); //ONENET -- NTP
  16.  
    //IPAddress timeServerIP(183,230,40,42); //ONENET -- NTP
学新通

这个文件看起来不像是作者写的,本文件定义比较规范。

TimerLibGitHub - PaulStoffregen/Time: Time library for Arduino

initNTP():Login to WiFi network and assign the time sync provider

  1.  
    // Login to WiFi network and assign the time sync provider
  2.  
    //登录WiFi网络并指定时间同步提供商
  3.  
    void initNTP() {
  4.  
     
  5.  
    // Login suceeded so set UDP local port
  6.  
    //登录成功,因此设置UDP本地端口
  7.  
    udp.begin(LOCALPORT); //初始化WiFiUDP库和网络设置,启动WiFiUDP套接字,侦听本地端口。
  8.  
     
  9.  
    // Set the time provider to NTP
  10.  
    //将时间提供程序设置为NTP
  11.  
    setSyncProvider(getNTPTime);
  12.  
    }

getNTPTime():NTP Time Provider Code

  1.  
    // NTP Time Provider Code
  2.  
    time_t getNTPTime() {
  3.  
     
  4.  
    int attempts = 10;
  5.  
     
  6.  
    // Try multiple attempts to return the NTP time
  7.  
    //尝试多次返回NTP时间
  8.  
    while (attempts--) {
  9.  
     
  10.  
    // Get a server from the pool
  11.  
    if(ntpServerName != NULL){
  12.  
    WiFi.hostByName(ntpServerName, timeServerIP); //从网站名获取IP地址
  13.  
    }
  14.  
    Serial.printf("Time server IP address: ");
  15.  
    Serial.println(timeServerIP);
  16.  
     
  17.  
    while (udp.parsePacket() > 0); // Discard any previously received packets
  18.  
    // 检查是否有UDP数据包传入,返回值数据包大小
  19.  
     
  20.  
    Serial.println("Transmitted NTP Request");
  21.  
    sendNTPpacket(timeServerIP);
  22.  
     
  23.  
    uint32_t beginWait = millis(); //返回运行毫秒数
  24.  
    while (millis() - beginWait < 1500) {
  25.  
    int size = udp.parsePacket();
  26.  
    if (size >= NTP_PACKET_SIZE) {
  27.  
    Serial.println("Received NTP Response");
  28.  
    udp.read(packetBuffer, NTP_PACKET_SIZE); // Read packet into the buffer
  29.  
    // 本函数可用于从设备接收到数据中读取数据。函数将会返回等待读取的数据字节数。
  30.  
    unsigned long secsSince1900;
  31.  
     
  32.  
    // Convert four bytes starting at location 40 to a long integer
  33.  
    //将从位置40开始的四个字节转换为长整数
  34.  
    secsSince1900 = (unsigned long) packetBuffer[40] << 24;
  35.  
    secsSince1900 |= (unsigned long) packetBuffer[41] << 16;
  36.  
    secsSince1900 |= (unsigned long) packetBuffer[42] << 8;
  37.  
    secsSince1900 |= (unsigned long) packetBuffer[43];
  38.  
     
  39.  
    Serial.println("Got the time");
  40.  
     
  41.  
    return secsSince1900 - 2208988800UL;
  42.  
    }
  43.  
    delay(10);
  44.  
    }
  45.  
    Serial.println("Retrying NTP request");
  46.  
    delay(4000);
  47.  
    }
  48.  
    Serial.println("No NTP Response");
  49.  
    return 0;
  50.  
    }
学新通

sendNTPpacket():Send an NTP request to the time server at the given address

  1.  
     
  2.  
    // Send an NTP request to the time server at the given address
  3.  
    //向指定地址的时间服务器发送NTP请求
  4.  
    unsigned long sendNTPpacket(IPAddress& address) {
  5.  
     
  6.  
    // Set all bytes in the buffer to 0
  7.  
    memset(packetBuffer, 0, NTP_PACKET_SIZE);
  8.  
     
  9.  
    // Initialize values needed to form NTP request
  10.  
    packetBuffer[0] = 0b11100011; // LI, Version, Mode
  11.  
    packetBuffer[1] = 0; // Stratum, or type of clock
  12.  
    packetBuffer[2] = 6; // Polling Interval
  13.  
    packetBuffer[3] = 0xEC; // Peer Clock Precision
  14.  
    // 8 bytes of zero for Root Delay & Root Dispersion
  15.  
    packetBuffer[12] = 49;
  16.  
    packetBuffer[13] = 0x4E;
  17.  
    packetBuffer[14] = 49;
  18.  
    packetBuffer[15] = 52;
  19.  
     
  20.  
    // All NTP fields have been given values, now
  21.  
    // you can send a packet requesting a timestamp:
  22.  
    udp.beginPacket(address, 123); // NTP requests are to port 123
  23.  
    udp.write(packetBuffer, NTP_PACKET_SIZE);
  24.  
    udp.endPacket();
  25.  
    }
学新通

get_weather()、updatetime()、hitokoto()、newsdisplay()、gettem()

get_weather()定义在disolayCode文件中。

get_weather()

图像定义在ImageData.c中,通过ImageData.h声明引用。

主要是右侧日期下方部分的显示。

  1.  
    /*天气信息*/
  2.  
    void get_weather(void){
  3.  
    String tubiao = actual.weather_name;
  4.  
    Serial.println(tubiao);
  5.  
    if(tubiao=="多云"||tubiao=="晴间多云"||tubiao=="大部多云"){
  6.  
    display.drawInvertedBitmap(280, 15, duoyun, 128, 128, GxEPD_BLACK);//画图
  7.  
    }else if(tubiao=="晴"){
  8.  
    display.drawInvertedBitmap(280, 15, qing, 128, 128, GxEPD_BLACK);//画图
  9.  
    }else if(tubiao=="阴"){
  10.  
    display.drawInvertedBitmap(280, 15, yin, 128, 128, GxEPD_BLACK);//画图
  11.  
    }else if(tubiao=="阵雨"){
  12.  
    display.drawInvertedBitmap(280, 15, zhenyu, 128, 128, GxEPD_BLACK);//画图
  13.  
    }else if(tubiao=="雷阵雨"){
  14.  
    display.drawInvertedBitmap(280, 15, leizhenyu, 128, 128, GxEPD_BLACK);//画图
  15.  
    }else if(tubiao=="雷阵雨伴有冰雹"){
  16.  
    display.drawInvertedBitmap(280, 15, leizhenyubanyoubingbao, 128, 128, GxEPD_BLACK);//画图
  17.  
    }else if(tubiao=="小雨"){
  18.  
    display.drawInvertedBitmap(280, 15, xiaoyu, 128, 128, GxEPD_BLACK);//画图
  19.  
    }else if(tubiao=="中雨"){
  20.  
    display.drawInvertedBitmap(280, 15, zhongyu, 128, 128, GxEPD_BLACK);//画图
  21.  
    }else if(tubiao=="大雨"){
  22.  
    display.drawInvertedBitmap(280, 15, dayu, 128, 128, GxEPD_BLACK);//画图
  23.  
    }else if(tubiao=="暴雨"||tubiao=="大暴雨"||tubiao=="特大暴雨"){
  24.  
    display.drawInvertedBitmap(280, 15, baoyu, 128, 128, GxEPD_BLACK);//画图
  25.  
    }else if(tubiao=="冻雨"){
  26.  
    display.drawInvertedBitmap(280, 15, dongyu, 128, 128, GxEPD_BLACK);//画图
  27.  
    }else if(tubiao=="雨夹雪"){
  28.  
    display.drawInvertedBitmap(280, 15, yujiaxue, 128, 128, GxEPD_BLACK);//画图
  29.  
    }else if(tubiao=="阵雪"){
  30.  
    display.drawInvertedBitmap(280, 15, zhenxue, 128, 128, GxEPD_BLACK);//画图
  31.  
    }else if(tubiao=="小雪"){
  32.  
    display.drawInvertedBitmap(280, 15, xiaoxue, 128, 128, GxEPD_BLACK);//画图
  33.  
    }else if(tubiao=="中雪"){
  34.  
    display.drawInvertedBitmap(280, 15, zhongxue, 128, 128, GxEPD_BLACK);//画图
  35.  
    }else if(tubiao=="大雪"){
  36.  
    display.drawInvertedBitmap(280, 15, daxue, 128, 128, GxEPD_BLACK);//画图
  37.  
    }else if(tubiao=="暴雪"){
  38.  
    display.drawInvertedBitmap(280, 15, baoxue, 128, 128, GxEPD_BLACK);//画图
  39.  
    }else if(tubiao=="浮尘"){
  40.  
    display.drawInvertedBitmap(280, 15, fuchen, 128, 128, GxEPD_BLACK);//画图
  41.  
    }else if(tubiao=="扬沙"||tubiao=="沙尘暴"||tubiao=="强沙尘暴"){
  42.  
    display.drawInvertedBitmap(280, 15, shachenbao, 128, 128, GxEPD_BLACK);//画图
  43.  
    }else if(tubiao=="雾"){
  44.  
    display.drawInvertedBitmap(280, 15, dawu, 128, 128, GxEPD_BLACK);//画图
  45.  
    }else if(tubiao=="霾"){
  46.  
    display.drawInvertedBitmap(280, 15, mai, 128, 128, GxEPD_BLACK);//画图
  47.  
    }else if(tubiao=="未知"){
  48.  
    display.drawInvertedBitmap(280, 15, weizhi, 128, 128, GxEPD_BLACK);//画图
  49.  
    }
  50.  
     
  51.  
    /*位置 温度*/
  52.  
    display.drawInvertedBitmap(280, 128, weizhi, 32, 28, GxEPD_RED);//画图
  53.  
    u8g2Fonts.setCursor(312, 150);
  54.  
    u8g2Fonts.setFont(chinese_city_gb2312);
  55.  
    u8g2Fonts.setForegroundColor(GxEPD_BLACK); // 设置前景色
  56.  
    u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // 设置背景色
  57.  
    u8g2Fonts.print(String(actual.city));
  58.  
    // u8g2Fonts.setCursor(283,222);
  59.  
    u8g2Fonts.setCursor(272,242);
  60.  
    u8g2Fonts.print("今天");
  61.  
    u8g2Fonts.setCursor(272,262);
  62.  
    u8g2Fonts.print("明天");
  63.  
    u8g2Fonts.setCursor(272,282);
  64.  
    u8g2Fonts.print("后天");
  65.  
    String text_day0, text_night0, dn0_s;
  66.  
    String text_day1, text_night1, dn1_s;
  67.  
    String text_day2, text_night2, dn2_s;
  68.  
    const char* dn0; const char* dn1; const char* dn2;
  69.  
     
  70.  
    if (strcmp(future.date0_text_day, future.date0_text_night) != 0) //今天
  71.  
    {
  72.  
    text_day0 = future.date0_text_day;
  73.  
    text_night0 = future.date0_text_night;
  74.  
    dn0_s = text_day0 "转" text_night0;
  75.  
    dn0 = dn0_s.c_str();
  76.  
    u8g2Fonts.setCursor(300, 242);
  77.  
    u8g2Fonts.print(dn0);
  78.  
    }
  79.  
    else
  80.  
    {
  81.  
    dn0 = future.date0_text_night;
  82.  
    u8g2Fonts.setCursor(300, 242);
  83.  
    u8g2Fonts.print(dn0);
  84.  
    }
  85.  
     
  86.  
    if (strcmp(future.date1_text_day, future.date1_text_night) != 0) //明天
  87.  
    {
  88.  
    text_day1 = future.date1_text_day;
  89.  
    text_night1 = future.date1_text_night;
  90.  
    dn1_s = text_day1 "转" text_night1;
  91.  
    dn1 = dn1_s.c_str();
  92.  
    u8g2Fonts.setCursor(300, 262);
  93.  
    u8g2Fonts.print(dn1);
  94.  
    }
  95.  
    else
  96.  
    {
  97.  
    dn1 = future.date1_text_night;
  98.  
    u8g2Fonts.setCursor(300, 262);
  99.  
    u8g2Fonts.print(dn1);
  100.  
    }
  101.  
     
  102.  
    if (strcmp(future.date2_text_day, future.date2_text_night) != 0) //后天
  103.  
    {
  104.  
    text_day2 = future.date2_text_day;
  105.  
    text_night2 = future.date2_text_night;
  106.  
    dn2_s = text_day2 "转" text_night2;
  107.  
    dn2 = dn2_s.c_str();
  108.  
    u8g2Fonts.setCursor(300, 282);
  109.  
    u8g2Fonts.print(dn2);
  110.  
    }
  111.  
    else
  112.  
    {
  113.  
    dn2 = future.date2_text_night;
  114.  
    u8g2Fonts.setCursor(300, 282);
  115.  
    u8g2Fonts.print(dn2);
  116.  
    }
  117.  
    //显示高低温
  118.  
    String high0, high1, high2, low0, low1, low2, hl0_s, hl1_s, hl2_s;
  119.  
    high0 = future.date0_high; high1 = future.date1_high; high2 = future.date2_high;
  120.  
    low0 = future.date0_low; low1 = future.date1_low; low2 = future.date2_low;
  121.  
    hl0_s = high0 "/" low0;
  122.  
    hl1_s = high1 "/" low1;
  123.  
    hl2_s = high2 "/" low2;
  124.  
    const char* hl0 = hl0_s.c_str();
  125.  
    const char* hl1 = hl1_s.c_str();
  126.  
    const char* hl2 = hl2_s.c_str();
  127.  
    u8g2Fonts.setCursor(373,242);
  128.  
    u8g2Fonts.print(hl0);
  129.  
    u8g2Fonts.setCursor(373,262);
  130.  
    u8g2Fonts.print(hl1);
  131.  
    u8g2Fonts.setCursor(373,282);
  132.  
    u8g2Fonts.print(hl2);
  133.  
     
  134.  
    }
学新通

updatetime()

  1.  
    #define STD_TIMEZONE_OFFSET 8
  2.  
    /*get time*/
  3.  
     
  4.  
    /*时间日期数字格式化*/
  5.  
    String pressNum(int num) {
  6.  
    if (num < 10 )
  7.  
    return "0" String(num);
  8.  
    else
  9.  
    return String(num);
  10.  
    }
  11.  
     
  12.  
     
  13.  
    void updatetime() {
  14.  
    String timedate,timetim="";
  15.  
    int weekdays, days, months,years,minutes,hours;
  16.  
    TimeChangeRule *tcr; // Pointer to the time change rule
  17.  
    time_t utc = now();
  18.  
    TimeChangeRule mySTD = {"", First, Sun, Jan, 0, STD_TIMEZONE_OFFSET * 60};
  19.  
    Timezone myTZ(mySTD, mySTD);
  20.  
    time_t localTime = myTZ.toLocal(utc, &tcr);
  21.  
    weekdays = weekday(localTime);
  22.  
    Serial.print("周");
  23.  
    Serial.println(weekdays);
  24.  
    // if(weekdays!=7){
  25.  
    // weekdays-=1;
  26.  
    // }else{
  27.  
    // weekdays=1;
  28.  
    // }
  29.  
    days = day(localTime);
  30.  
    months = month(localTime);
  31.  
    years = year(localTime);
  32.  
    timedate =String(pressNum(months)) ;
  33.  
    timedate = "月" ;
  34.  
     
  35.  
    // if(weekdays==0) weekdays=7;
  36.  
    minutes = minute(localTime);
  37.  
    hours = hour(localTime) ; //12 hour format use : hourFormat12(localTime) isPM()/isAM()
  38.  
    timetim="星期";
  39.  
    if(weekdays==2)timetim ="一";
  40.  
    else if(weekdays==3)timetim ="二";
  41.  
    else if(weekdays==4)timetim ="三";
  42.  
    else if(weekdays==5)timetim ="四";
  43.  
    else if(weekdays==6)timetim ="五";
  44.  
    else if(weekdays==7)timetim ="六";
  45.  
    else if(weekdays==1)timetim ="天";
  46.  
    timetim =" ";
  47.  
    timetim =String(hours);
  48.  
    timetim =" 点 ";
  49.  
    if(minutes<10){
  50.  
    timetim ="0";
  51.  
    }
  52.  
    timetim =String(minutes);
  53.  
    Serial.print(String(years) "-" String(months) "-" String(days) "-");
  54.  
    Serial.println(timetim);
  55.  
     
  56.  
    if(days<10){
  57.  
    display.drawInvertedBitmap(301, 144, ling, 48, 66, GxEPD_RED);//画图
  58.  
    if(days==1){
  59.  
    display.drawInvertedBitmap(349, 144, yi, 18, 66, GxEPD_RED);//画图
  60.  
    }else if(days==2){
  61.  
    display.drawInvertedBitmap(349, 144, er, 48, 66, GxEPD_RED);//画图
  62.  
    }else if(days==3){
  63.  
    display.drawInvertedBitmap(349, 144, san, 48, 66, GxEPD_RED);//画图
  64.  
    }else if(days==4){
  65.  
    display.drawInvertedBitmap(349, 144, si, 48, 66, GxEPD_RED);//画图
  66.  
    }else if(days==5){
  67.  
    display.drawInvertedBitmap(349, 144, wu, 48, 66, GxEPD_RED);//画图
  68.  
    }else if(days==6){
  69.  
    display.drawInvertedBitmap(349, 144, liu, 48, 66, GxEPD_RED);//画图
  70.  
    }else if(days==7){
  71.  
    display.drawInvertedBitmap(349, 144, qi, 48, 66, GxEPD_RED);//画图
  72.  
    }else if(days==8){
  73.  
    display.drawInvertedBitmap(349, 144, ba, 48, 66, GxEPD_RED);//画图
  74.  
    }else if(days==9){
  75.  
    display.drawInvertedBitmap(349, 144, jiu, 48, 66, GxEPD_RED);//画图
  76.  
    }
  77.  
     
  78.  
    }else if(days>=10&&days<20){
  79.  
    display.drawInvertedBitmap(301, 144, yi, 18, 66, GxEPD_RED);//画图
  80.  
    if(days==10){
  81.  
    display.drawInvertedBitmap(349, 144, ling, 48, 66, GxEPD_RED);//画图
  82.  
    }else if(days==11){
  83.  
    display.drawInvertedBitmap(349, 144, yi, 18, 66, GxEPD_RED);//画图
  84.  
    }else if(days==12){
  85.  
    display.drawInvertedBitmap(349, 144, er, 48, 66, GxEPD_RED);//画图
  86.  
    }else if(days==13){
  87.  
    display.drawInvertedBitmap(349, 144, san, 48, 66, GxEPD_RED);//画图
  88.  
    }else if(days==14){
  89.  
    display.drawInvertedBitmap(349, 144, si, 48, 66, GxEPD_RED);//画图
  90.  
    }else if(days==15){
  91.  
    display.drawInvertedBitmap(349, 144, wu, 48, 66, GxEPD_RED);//画图
  92.  
    }else if(days==16){
  93.  
    display.drawInvertedBitmap(349, 144, liu, 48, 66, GxEPD_RED);//画图
  94.  
    }else if(days==17){
  95.  
    display.drawInvertedBitmap(349, 144, qi, 48, 66, GxEPD_RED);//画图
  96.  
    }else if(days==18){
  97.  
    display.drawInvertedBitmap(349, 144, ba, 48, 66, GxEPD_RED);//画图
  98.  
    }else if(days==19){
  99.  
    display.drawInvertedBitmap(349, 144, jiu, 48, 66, GxEPD_RED);//画图
  100.  
    }
  101.  
    }else if(days>=20&&days<30){
  102.  
    display.drawInvertedBitmap(301, 144, er, 48, 66, GxEPD_RED);//画图
  103.  
    if(days==20){
  104.  
    display.drawInvertedBitmap(349, 144, ling, 48, 66, GxEPD_RED);//画图
  105.  
    }else if(days==21){
  106.  
    display.drawInvertedBitmap(349, 144, yi, 18, 66, GxEPD_RED);//画图
  107.  
    }else if(days==22){
  108.  
    display.drawInvertedBitmap(349, 144, er, 48, 66, GxEPD_RED);//画图
  109.  
    }else if(days==23){
  110.  
    display.drawInvertedBitmap(349, 144, san, 48, 66, GxEPD_RED);//画图
  111.  
    }else if(days==24){
  112.  
    display.drawInvertedBitmap(349, 144, si, 48, 66, GxEPD_RED);//画图
  113.  
    }else if(days==25){
  114.  
    display.drawInvertedBitmap(349, 144, wu, 48, 66, GxEPD_RED);//画图
  115.  
    }else if(days==26){
  116.  
    display.drawInvertedBitmap(349, 144, liu, 48, 66, GxEPD_RED);//画图
  117.  
    }else if(days==27){
  118.  
    display.drawInvertedBitmap(349, 144, qi, 48, 66, GxEPD_RED);//画图
  119.  
    }else if(days==28){
  120.  
    display.drawInvertedBitmap(349, 144, ba, 48, 66, GxEPD_RED);//画图
  121.  
    }else if(days==29){
  122.  
    display.drawInvertedBitmap(349, 144, jiu, 48, 66, GxEPD_RED);//画图
  123.  
    }
  124.  
    }else{
  125.  
    display.drawInvertedBitmap(301, 144, san, 48, 66, GxEPD_RED);//画图
  126.  
    if(days==30){
  127.  
    display.drawInvertedBitmap(349, 144, ling, 48, 66, GxEPD_RED);//画图
  128.  
    }else if(days==31){
  129.  
    display.drawInvertedBitmap(349, 144, yi, 18, 66, GxEPD_RED);//画图
  130.  
    }
  131.  
    }
  132.  
    u8g2Fonts.setFont(chinese_city_gb2312);
  133.  
    u8g2Fonts.setForegroundColor(GxEPD_BLACK); // 设置前景色
  134.  
    u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // 设置背景色
  135.  
    u8g2Fonts.setCursor(300, 30);//标记:位置需要修改
  136.  
    u8g2Fonts.print(timetim);
  137.  
    }
学新通

hitokoto()一言

  1.  
    void hitokoto(){
  2.  
    // display.drawRect(0, 0, 38, 12,1);
  3.  
    u8g2Fonts.setFont(chinese_city_gb2312);
  4.  
    u8g2Fonts.setForegroundColor(GxEPD_RED); // 设置前景色
  5.  
    u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // 设置背景色
  6.  
    u8g2Fonts.setCursor(42, 12);
  7.  
    u8g2Fonts.print(String(yiyan.hitokoto));
  8.  
    display.drawInvertedBitmap(0, 0, yiyanp, 38, 12, GxEPD_RED);//画图
  9.  
     
  10.  
    }

newsdisplay()新闻

  1.  
    void newsdisplay(){
  2.  
    display.drawLine(269, 25, 269, 296, 0);
  3.  
    u8g2Fonts.setFont(chinese_city_gb2312);
  4.  
    u8g2Fonts.setForegroundColor(GxEPD_BLACK); // 设置前景色
  5.  
    u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // 设置背景色
  6.  
    if(udc%3==0){
  7.  
    display.drawInvertedBitmap(75, 16, weibo, 32, 32, GxEPD_BLACK);//画图
  8.  
    u8g2Fonts.setCursor(106,38);
  9.  
    u8g2Fonts.print("微博热点");
  10.  
    }else if(udc%3==1){
  11.  
    display.drawInvertedBitmap(75, 16, toutiao, 32, 32, GxEPD_BLACK);//画图
  12.  
    u8g2Fonts.setCursor(106,38);
  13.  
    u8g2Fonts.print("央视新闻");
  14.  
     
  15.  
    }else{
  16.  
    display.drawInvertedBitmap(75, 16, zhihu, 32, 32, GxEPD_BLACK);//画图
  17.  
    u8g2Fonts.setCursor(106,38);
  18.  
    u8g2Fonts.print("知乎热榜");
  19.  
    }
  20.  
    String news_title,tt="";
  21.  
    for(int i=0;i<11;i ){ //11行
  22.  
    u8g2Fonts.setCursor(4,60 i*22);
  23.  
    news_title =String(xinwen.title[i]);
  24.  
    if(news_title.length()>54){
  25.  
    for(int j=0;j<54;j ){
  26.  
    tt =news_title[j];
  27.  
    }
  28.  
    u8g2Fonts.print(tt);
  29.  
    }else{
  30.  
    u8g2Fonts.print(news_title);
  31.  
    }
  32.  
    tt="";
  33.  
    }
  34.  
     
  35.  
    }
学新通

gettem()温湿度

  1.  
    dht11 DHT11;
  2.  
    void gettem(){
  3.  
    DHT11.read(21);
  4.  
    String temperature=String(DHT11.temperature) "℃";
  5.  
    String humidity = String(DHT11.humidity) "%";
  6.  
    u8g2Fonts.setFont(chinese_city_gb2312);
  7.  
    u8g2Fonts.setForegroundColor(GxEPD_BLACK); // 设置前景色
  8.  
    u8g2Fonts.setBackgroundColor(GxEPD_WHITE); // 设置背景色
  9.  
    u8g2Fonts.setCursor(272,222);
  10.  
    u8g2Fonts.print("室内");
  11.  
    display.drawInvertedBitmap(312, 210, wendu, 16, 16, GxEPD_BLACK);//画图
  12.  
    u8g2Fonts.setCursor(330,222);
  13.  
    u8g2Fonts.print(temperature);
  14.  
    display.drawInvertedBitmap(358, 210, shidu, 16, 16, GxEPD_BLACK);//画图
  15.  
    u8g2Fonts.setCursor(376,222);
  16.  
    u8g2Fonts.print(humidity);
  17.  
    }
学新通

不太会的地方        ①wifi配网        ②获取时间        ③WiFiUdp

学习吧,我的宝~ ~

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbfejf
系列文章
更多 icon
同类精品
更多 icon
继续加载