久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1645|回復: 0
打印 上一主題 下一主題
收起左側

【零知ESP8266教程】快速入門21 世界時鐘demo

[復制鏈接]
跳轉到指定樓層
樓主
上次分享了一個本地時鐘,小伙伴覺得不fashion,所以思前想后,做一個世界時鐘,來撐撐場面,也算是一個小拓展。這次,我們一起制作世界時鐘!
一、硬件
電腦,windows系統
零知ESP8266開發板
OLED SSD1306模塊
micro-usb線
杜邦線若干
二、連線









三、軟件庫的查找安裝
(1)查找:可以在零知實驗室查看“無線”下載安裝,也可在github查找安裝。
(亦可評論留言,私發給你)

OLED和WeatherStation

(2)安裝:可以在零知實驗室搜索:本地庫,即可出現安裝教程。
(3)安裝完成后,打開零知開源軟件,選擇對應的開發板,如圖:


(4)我們新建工程,燒寫以下代碼:



  1. #include <ESP8266WiFi.h>
  2. #include <ESP8266HTTPClient.h>
  3. #include <Ticker.h>
  4. #include <JsonListener.h>
  5. #include <SSD1306Wire.h>
  6. #include <OLEDDisplayUi.h>
  7. #include <Wire.h>
  8. #include <WorldClockClient.h>
  9. #include "icons.h"
  10. #include "fonts.h"



  11. /***************************
  12. * Begin Settings
  13. **************************/
  14. // WIFI
  15. const char* WIFI_SSID = "xx";//在這里寫入你的WIFI名字
  16. const char* WIFI_PWD = "xx"; //寫WIFI密碼

  17. // Setup
  18. const int UPDATE_INTERVAL_SECS = 10 * 60; // Update every 10 minutes

  19. // Display Settings
  20. const int I2C_DISPLAY_ADDRESS = 0x3c;
  21. const int SDA_PIN = D3; //
  22. const int SDC_PIN = D4;

  23. // TimeClient settings


  24. // Initialize the oled display for address 0x3c
  25. // sda-pin=14 and sdc-pin=12

  26. SSD1306Wire  display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
  27. OLEDDisplayUi ui     ( &display );

  28. /***************************
  29. * End Settings
  30. **************************/
  31. //String timeZoneIds [] = {"America/New_York", "Europe/London", "Europe/Paris", "Australia/Sydney", ""};
  32. //WorldClockClient worldClockClient("de", "CH", "E, dd. MMMMM yyyy", 4, timeZoneIds);
  33. //
  34. String timeZoneIds [] = {"America/New_York", "Europe/London", "Europe/Paris", "Australia/Sydney", "Asia/Shanghai"};
  35. WorldClockClient worldClockClient("zh", "CN", "E, dd. MMMMM yyyy", 5, timeZoneIds);

  36. // flag changed in the ticker function every 10 minutes
  37. bool readyForUpdate = false;

  38. String lastUpdate = "--";

  39. Ticker ticker;


  40. void updateData(OLEDDisplay *display) {
  41.   drawProgress(display, 50, "Updating Time...");
  42.   worldClockClient.updateTime();
  43.   drawProgress(display, 100, "Done...");
  44.   readyForUpdate = false;
  45.   delay(1000);
  46. }

  47. void drawProgress(OLEDDisplay *display, int percentage, String label) {
  48.   display->clear();
  49.   display->setTextAlignment(TEXT_ALIGN_CENTER);
  50.   display->setFont(ArialMT_Plain_10);
  51.   display->drawString(64, 10, label);
  52.   display->drawProgressBar(10, 28, 108, 12, percentage);
  53.   display->display();
  54. }

  55. void drawClock(OLEDDisplay *display, int x, int y, int timeZoneIndex, String city, const uint8_t* icon) {
  56.   display->setTextAlignment(TEXT_ALIGN_LEFT);
  57.   display->setFont(ArialMT_Plain_10);
  58.   display->drawString(x + 60, y + 5, city);
  59.   display->setFont(Crushed_Plain_36);
  60.   display->drawXbm(x, y, 60, 60, icon);
  61.   display->drawString(x + 60, y + 15, worldClockClient.getHours(timeZoneIndex) + ":" + worldClockClient.getMinutes(timeZoneIndex));

  62. }

  63. void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  64.   drawClock(display, x, y, 0, "New York",  new_york_bits); //紐約
  65. }

  66. void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  67.   drawClock(display, x, y, 1, "London",  london_bits); //倫敦
  68. }

  69. void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  70.   drawClock(display, x, y, 2, "Paris",  paris_bits);  //巴黎
  71. }

  72. void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  73.   drawClock(display, x, y, 3, "Sydney",  sydney_bits); //悉尼
  74. }

  75. void drawFrame5(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
  76.   drawClock(display, x, y, 4, "Beijing",  beijing_bits); //北京
  77. }

  78. void setReadyForWeatherUpdate() {
  79.   Serial.println("Setting readyForUpdate to true");
  80.   readyForUpdate = true;
  81. }

  82. // this array keeps function pointers to all frames
  83. // frames are the single views that slide from right to left
  84. FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4, drawFrame5};
  85. int numberOfFrames = 5;

  86. void setup() {
  87.   Serial.begin(115200);
  88.   Serial.println();
  89.   Serial.println();

  90.   // initialize dispaly
  91.   display.init();
  92.   display.clear();
  93.   display.display();

  94.   //display.flipScreenVertically();
  95.   display.setFont(ArialMT_Plain_10);
  96.   display.setTextAlignment(TEXT_ALIGN_CENTER);
  97.   display.setContrast(255);

  98.   WiFi.begin(WIFI_SSID, WIFI_PWD);

  99.   int counter = 0;
  100.   while (WiFi.status() != WL_CONNECTED) {
  101.     delay(500);
  102.     Serial.print(".");
  103.     display.clear();
  104.     display.drawString(64, 10, "Connecting to WiFi");
  105.     display.drawXbm(46, 30, 8, 8, counter % 3 == 0 ? activeSymbol : inactiveSymbol);
  106.     display.drawXbm(60, 30, 8, 8, counter % 3 == 1 ? activeSymbol : inactiveSymbol);
  107.     display.drawXbm(74, 30, 8, 8, counter % 3 == 2 ? activeSymbol : inactiveSymbol);
  108.     display.display();

  109.     counter++;
  110.   }

  111.   ui.setTargetFPS(30);

  112.   // You can change this to
  113.   // TOP, LEFT, BOTTOM, RIGHT
  114.   ui.setIndicatorPosition(BOTTOM);

  115.   // Defines where the first frame is located in the bar.
  116.   ui.setIndicatorDirection(LEFT_RIGHT);

  117.   // You can change the transition that is used
  118.   // SLIDE_LEFT, SLIDE_RIGHT, SLIDE_TOP, SLIDE_DOWN
  119.   ui.setFrameAnimation(SLIDE_LEFT);

  120.   // Add frames
  121.   ui.setFrames(frames, numberOfFrames);
  122.    
  123.   ui.setTimePerFrame(2*1000); // Setup frame display time to 10 sec

  124.   // Inital UI takes care of initalising the display too.
  125.   ui.init();

  126.   Serial.println("");

  127.   updateData(&display);

  128.   ticker.attach(UPDATE_INTERVAL_SECS, setReadyForWeatherUpdate);

  129. }

  130. void loop() {

  131.   if (readyForUpdate && ui.getUiState()->frameState == FIXED) {
  132.     updateData(&display);
  133.   }

  134.   int remainingTimeBudget = ui.update();

  135.   if (remainingTimeBudget > 0) {
  136.     // You can do some work here
  137.     // Don't do stuff if you are below your
  138.     // time budget.
  139.     delay(remainingTimeBudget);
  140.   }

  141. }
復制代碼

(5)驗證代碼,然后上傳

四、結果



同時OLED就可以顯示世界時鐘的效果:


還有效果視頻哦!

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 美女福利视频一区 | 日韩欧美一级精品久久 | 欧美午夜在线 | 国产精品九九九 | 国产精品久久久久久久久久免费看 | 免费在线观看黄视频 | 欧美国产一区二区三区 | 一级免费毛片 | 自拍第1页| 亚洲精品在线看 | 午夜精品久久久久久久99黑人 | 欧美在线一区二区三区 | 日韩中文字幕视频 | 日本电影一区二区 | 毛片一区二区 | 欧美日产国产成人免费图片 | 日本免费网 | 日韩av在线一区 | 国产精品完整版 | 青娱乐av| 黄色一级视频 | 国产一区二区精品 | 伊人久久综合 | 欧美成人精品激情在线观看 | 少妇性l交大片免费一 | 狠狠影院 | 国产精品久久久久久久午夜片 | 国产乱码一二三区精品 | 国产中文字幕在线 | 国产精品3区 | 婷婷激情综合 | 成人在线播放网址 | 激情五月婷婷 | 国产成人午夜电影网 | 二区在线观看 | 91久久国产精品 | 亚洲午夜精品视频 | 一级日批片 | 香蕉久久av | 国产精品小视频在线观看 | 一级毛片网 |