weixin_44587339 2020-05-20 21:04 采纳率: 0%
浏览 425

Arduino关于天气和闹钟的问题和日期在OLED上打印的问题

Arduino关于天气和闹钟的问题和日期在OLED上打印的问题
在韩留学生一枚,每天在论坛搜索关于这方面的技术问题,无奈底子不是很扎实,都是靠自学,老师布置的作业也没有教很多,就让我们自己摸索,基本的功能我差不多都做了,要加一些没学过的 老师给了个json的网站好像是可以换算天气代码的那种,然后让我们添加一下天气和日期,还有闹钟,我之前想用strcmp函数实现闹钟,因为我们闹钟并不要求响,就是比如到7点了我插在面包板上的灯会亮这种,但是好像不行,如果行的话还请大神指点迷津,希望哪位贵人能帮帮小弟,每天盲人走路很是难受 小弟QQ:809886541
用的设备是 Wemos D1 和DHT11 还有OLED12864
附上代码片

#include <NTPClient.h>
// change next line to use with another board/shield
#include <ESP8266WiFi.h>
//#include <WiFi.h> // for WiFi shield
//#include <WiFi101.h> // for WiFi 101 shield or MKR1000
#include <WiFiUdp.h>
#include <Wire.h>
#include <ACROBOTIC_SSD1306.h>

#include "DHT.h"

#define DHTPIN D5     // Digital pin connected to the DHT sensor
// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 1
DHT dht(DHTPIN, DHTTYPE);


const char *ssid     = "101dedasb";
const char *password = "Zhl980108.";

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);

void setup(){
  Serial.begin(115200);

  WiFi.begin(ssid, password);

  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  dht.begin();
  timeClient.begin();
  timeClient.setTimeOffset(9*60*60);


  Wire.begin();  
  oled.init();                      // Initialze SSD1306 OLED display
  oled.clearDisplay();
  oled.setTextXY(0,6);              // Set cursor position, start of line 0
  oled.putString("Rolex");// Clear screen
  oled.setTextXY(1,0);              // Set cursor position, start of line 0
  oled.putString("Time:");

}

void loop() {
  timeClient.update();

  oled.setTextXY(2,0);              // Set cursor position, start of line 1
  oled.putString(timeClient.getFormattedTime());

  Serial.println(timeClient.getFormattedTime());

  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  char txt[32];
  sprintf(txt, "temp:%.2f C", t);
  oled.setTextXY(6,0);              // Set cursor position, start of line 0
  oled.putString(txt);

  sprintf(txt, "humi:%.2f %%", h);
  oled.setTextXY(7,0);              // Set cursor position, start of line 0
  oled.putString(txt);
  delay(1000);
char xx = Serial.read();

switch (xx)
{
case '1':
 timeClient.setTimeOffset(9*60*60);
 timeClient.update();

  oled.setTextXY(2,0);              // Set cursor position, start of line 1
  oled.putString(timeClient.getFormattedTime());

  Serial.println(timeClient.getFormattedTime());
  delay(1000);
  break;
case '2':
 timeClient.setTimeOffset(8*60*60);
 timeClient.update();

  oled.setTextXY(2,0);              // Set cursor position, start of line 1
  oled.putString(timeClient.getFormattedTime());

  Serial.println(timeClient.getFormattedTime());
  delay(1000);
  break;


delay(1000);
}
}

  • 写回答

1条回答 默认 最新

  • zqbnqsdsmd 2020-05-21 09:04
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘