查看: 2511|回复: 3

小e 电子表

[复制链接]
  • TA的每日心情
    奋斗
    2016-4-18 10:19
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2016-4-21 23:01:13 | 显示全部楼层 |阅读模式
    分享到:
    本帖最后由 zhenlinuaa 于 2016-4-22 22:27 编辑

    闲来无事,用小e做了个电子表,时间从网络自动获取,运行界面如下图所示:
    001 (2).jpg

    源代码:
    1. #include <ESP8266WiFi.h>
    2. #include <time.h>
    3. #include <Wire.h>
    4. #include "SSD1306.h"


    5. const char* ssid = "xxx"; //wifi name
    6. const char* password = "xxxxx"; //wifi password

    7. // Initialize the oled display for address 0x3c
    8. //I2C-ADD=0X3C, sda-pin=2 and sdc-pin=14
    9. SSD1306 oled(0x3c, 2, 14);

    10. void setup()
    11. {
    12.         Serial.begin(115200);

    13.         Serial.setDebugOutput(true);

    14.         WiFi.mode(WIFI_STA);
    15.         WiFi.begin(ssid, password);
    16.         Serial.println("\nConnecting to WiFi");
    17.         while (WiFi.status() != WL_CONNECTED)
    18.         {
    19.                 Serial.print(".");
    20.                 delay(1000);
    21.         }

    22.         configTime(8 * 3600, 0, "pool.ntp.org", "time.nist.gov");
    23.         Serial.println("\nWaiting for time");
    24.         while (!time(nullptr))
    25.         {
    26.                 Serial.print(".");
    27.                 delay(1000);
    28.         }
    29.         Serial.println("");

    30.         oled.init();
    31.         oled.flipScreenVertically();
    32. }

    33. void loop()
    34. {
    35.         time_t now = time(nullptr);
    36.         String currenttiem = ctime(&now);
    37.         Serial.println(currenttiem);
    38.         String hms = currenttiem.substring(11, 19);
    39.         String date = currenttiem.substring(0, 11)+currenttiem.substring(20);

    40.         oled.setFont(ArialMT_Plain_16);
    41.         oled.setTextAlignment(TEXT_ALIGN_LEFT);
    42.         oled.drawString(0, 0, date);

    43.         oled.setFont(ArialMT_Plain_24);
    44.         oled.setTextAlignment(TEXT_ALIGN_LEFT);
    45.         oled.drawString(0, 30, hms);

    46.         oled.display();
    47.         oled.clear();

    48.         delay(1000);
    49. }
    复制代码
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    2018-11-15 17:06
  • 签到天数: 30 天

    连续签到: 1 天

    [LV.5]常住居民I

    发表于 2016-5-13 16:43:52 | 显示全部楼层
    不错
    回复 支持 反对

    使用道具 举报

  • TA的每日心情

    2016-6-8 19:50
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2016-5-26 18:10:15 | 显示全部楼层
    src\led.cpp:4:21: fatal error: SSD1306.h: No such file or directory
    #include "SSD1306.h"
    ^
    compilation terminated.
    scons: *** [.pioenvs\esp_wroom_02\src\led.o] Error 1
    [ ERROR ] Took 5.02 seconds
    回复 支持 反对

    使用道具 举报

  • TA的每日心情

    2016-6-8 19:50
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2016-6-8 20:10:28 | 显示全部楼层
    https://github.com/squix78/esp8266-oled-ssd1306
    加库
    回复 支持 反对

    使用道具 举报

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

    本版积分规则

    关闭

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

    手机版|小黑屋|与非网

    GMT+8, 2024-4-27 12:48 , Processed in 0.141064 second(s), 22 queries , MemCache On.

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

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.