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);
}
}