diff --git a/d4.ino b/d4.ino index 74f966a..984418e 100644 --- a/d4.ino +++ b/d4.ino @@ -1,6 +1,186 @@ +#include +#include "M5StickCPlus.h" +#include +#include +#include +#include +#include + +char str[100]; +/* +When this code write to M5Stick, remove GND pin from M5Stick. +Then Err won't occurred +*/ +//LED of M5StickC voltage is opposite to M5Stack +const char* ssid = "miura2g"; +const char* password = "jikken2022"; +const char* host = "notify-api.line.me"; +const char* token = ""; +const String endpoint = "http://api.openweathermap.org/data/2.5/weather?q=tokyo,jp&APPID="; +const String key = ""; +int weathertime; +int weatherflag=0; +int forecast=0; +char timenow[30]; +int nowy,nowmon,nowd,nowh,nowm,nows,reg; +int systime=millis()/1000; + +#define LED_PIN 10 +#define DOOR_PIN 26 +#define KEY_PIN 0 +#define KEY_TIME 3 //seconds +#define weatherapi 30 //minutes +//regular weather notice time +#define seth 7 //hour +#define setm 0 //min +#define ntptime 5//min void setup() { + M5.begin(); + M5.Lcd.setRotation(3); + pinMode(DOOR_PIN, INPUT_PULLUP); + pinMode(KEY_PIN, INPUT_PULLUP); + pinMode(LED_PIN,OUTPUT); + M5.Lcd.fillScreen(BLACK); + //wifi + M5.Lcd.printf("WIFI START:%s ", ssid); + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + M5.Lcd.print("."); + } + M5.Lcd.println(" - READY"); + //weather + weatherget(); + weathertime=millis(); + ntpsetup(); } +int unflag=0; -void loop() { -} +void loop(){ + M5.update(); + ntpget(); + if(digitalRead(KEY_PIN)==1){ + digitalWrite(LED_PIN, LOW); + M5.Lcd.fillScreen(GREEN); + M5.Lcd.setCursor(10,10); + M5.Lcd.setTextColor(BLACK); + M5.Lcd.setTextSize(5); + M5.Lcd.print("Unlock"); + M5.Lcd.setCursor(10,80); + M5.Lcd.setTextSize(3); + M5.Lcd.println(timenow); + //weather + if(weatherflag==1&&unflag==0){ + unotice(); + unflag=1; + unotice(); + } + }else{ + digitalWrite(LED_PIN, HIGH); + M5.Lcd.fillScreen(BLACK); + M5.Lcd.setCursor(10,10); + M5.Lcd.setTextColor(WHITE); + M5.Lcd.setTextSize(5); + M5.Lcd.print("Locked"); + M5.Lcd.setCursor(10,80); + M5.Lcd.setTextSize(3); + M5.Lcd.println(timenow); + unflag=0; + + } + //display Umbrella in key status page + if(weatherflag==1){ + M5.Lcd.setCursor(10,50); + M5.Lcd.setTextSize(4); + M5.Lcd.setTextColor(RED); + M5.Lcd.print("Umbrella"); + }else{ + M5.Lcd.setCursor(10,50); + M5.Lcd.setTextSize(3); + M5.Lcd.setTextColor(BLUE); + M5.Lcd.print("Good Weather"); + } + if(digitalRead(DOOR_PIN)==1){ + //weather + if(weatherflag==1){ + unotice(); + unotice(); + } + while(1){ + ntpget(); + M5.Lcd.fillScreen(BLUE); + M5.Lcd.setTextColor(BLACK); + M5.Lcd.setTextSize(5); + M5.Lcd.setCursor(10,10); + M5.Lcd.printf("Open"); + M5.Lcd.setCursor(10,80); + M5.Lcd.setTextSize(3); + M5.Lcd.println(timenow); + if(digitalRead(DOOR_PIN)==0){ + break; + } + delay(1000); + } + int seccount=0; + while(seccount