move
This commit is contained in:
parent
3a2aedb11a
commit
42eae6ec9c
2
.vscode/arduino.json
vendored
2
.vscode/arduino.json
vendored
@ -1,6 +1,6 @@
|
||||
{
|
||||
"board": "esp8266:esp8266:generic",
|
||||
"configuration": "CpuFrequency=80,FlashFreq=40,FlashMode=qio,UploadSpeed=921600,FlashSize=512K0,ResetMethod=ck,Debug=Disabled,DebugLevel=None____",
|
||||
"configuration": "xtal=80,vt=flash,exception=disabled,ssl=all,ResetMethod=ck,CrystalFreq=26,FlashFreq=40,FlashMode=qio,eesz=4M1M,led=2,sdk=nonosdk221,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=921600",
|
||||
"sketch": "frontend.ino",
|
||||
"port": "/dev/ttyUSB0"
|
||||
}
|
97
frontend.ino
97
frontend.ino
@ -5,8 +5,6 @@
|
||||
#include "SSD1306Brzo.h"
|
||||
#include "wifi.h"
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <FS.h>
|
||||
|
||||
String inTemp,outTemp,pressure,humid;
|
||||
const unsigned short int onTime=6, offTime=23, beepDelay=60, timeOffset=3;
|
||||
@ -19,20 +17,27 @@ int alarmStop(0);
|
||||
WiFiUDP ntpUDP;
|
||||
NTPClient timeClient(ntpUDP);
|
||||
SSD1306Brzo display(0x3C, 5, 4);
|
||||
|
||||
void demo();
|
||||
void setup(){
|
||||
Serial.begin(115200);
|
||||
//==DISPLAY INIT==
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
display.setContrast(255);
|
||||
// display.invertDisplay();
|
||||
display.clear();
|
||||
display.fillRect(0,0,128,64);
|
||||
display.display();
|
||||
delay(3000);
|
||||
if (!digitalRead(0)) //button
|
||||
demo(120000);
|
||||
Serial.begin(115200);
|
||||
|
||||
//==WIFI CONNECT==
|
||||
WiFi.mode(WIFI_STA);
|
||||
//==NTP INIT==
|
||||
timeClient.begin();
|
||||
timeClient.setTimeOffset(timeOffset*3600);
|
||||
netTasks();
|
||||
// SPIFFS.begin();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
@ -46,14 +51,13 @@ void loop(){
|
||||
noTone(15);
|
||||
lastBeep = timeClient.getHours()*60;
|
||||
netTasks();
|
||||
// demo(12000);
|
||||
}
|
||||
else {
|
||||
delay(500);
|
||||
}
|
||||
checkAlarm();
|
||||
}
|
||||
|
||||
|
||||
void checkAlarm()
|
||||
{
|
||||
for (int i(0);i<10;i++)
|
||||
@ -78,7 +82,6 @@ void checkAlarm()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void netTasks() {
|
||||
HTTPClient http;
|
||||
WiFi.forceSleepWake();
|
||||
@ -141,25 +144,38 @@ void mainScreen() {
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
void displayStatus(int state){
|
||||
display.clear();
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
switch (state) {
|
||||
case 0:
|
||||
display.drawString(64, 22, "Connected!");
|
||||
break;
|
||||
case 1:
|
||||
display.drawString(64, 22, "Connecting...");
|
||||
break;
|
||||
case 2:
|
||||
display.drawString(64, 22, "Not connected!");
|
||||
void displayStatus(){
|
||||
bool run(true);
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(0, 53, "we will die in 10s! :0");
|
||||
break;
|
||||
int x(0),y(0);
|
||||
bool xd(false);//false - right, true - left
|
||||
|
||||
while (run)
|
||||
{
|
||||
display.clear();
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
display.fillRect(x,y,30,50);
|
||||
if (x > 128-30)
|
||||
xd = true;
|
||||
if (x < 0)
|
||||
xd = false;
|
||||
if (xd) {
|
||||
x--;
|
||||
} else {
|
||||
x++;
|
||||
}
|
||||
|
||||
display.drawString(1, 52, ssid);
|
||||
|
||||
}
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
run = false;
|
||||
}
|
||||
display.display();
|
||||
}
|
||||
|
||||
}
|
||||
void updateNtp() {
|
||||
while (!timeClient.update())
|
||||
Serial.println(timeClient.getHours());
|
||||
@ -174,15 +190,34 @@ bool nightMode() {
|
||||
void wifiConnect(bool boot) {
|
||||
int beginMillis = millis();
|
||||
WiFi.begin(ssid, password);
|
||||
while (WiFi.status() != WL_CONNECTED && millis() - beginMillis < 30000) {
|
||||
delay(250);
|
||||
Serial.print(".");
|
||||
displayStatus();
|
||||
}
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
delay(10000);
|
||||
ESP.reset();
|
||||
} else {
|
||||
Serial.print("Connected to " + String(ssid) + "; IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
|
||||
|
||||
void demo(int duration)
|
||||
{
|
||||
short xp(0),yp(0),xd(1),yd(1);
|
||||
unsigned int startTime = millis();
|
||||
bool run(true);
|
||||
while (run) {
|
||||
if ((xp > 128) || (xp < 0))
|
||||
{
|
||||
xd = xd * -1;
|
||||
}
|
||||
if ((yp > 64) || (yp < 0))
|
||||
{
|
||||
yd = yd * -1;
|
||||
}
|
||||
xp+=xd;
|
||||
yp+=yd;
|
||||
|
||||
delay(10);
|
||||
display.clear();
|
||||
display.fillCircle(xp,yp,10);
|
||||
display.display();
|
||||
|
||||
if (millis() - startTime > duration)
|
||||
run = false;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user