Created
December 3, 2020 10:05
-
-
Save gn-spawn/4efe4d226c9ca7f2efd0315274a1ddf4 to your computer and use it in GitHub Desktop.
m5nest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5StickC.h> | |
#include <esp8266-google-home-notifier.h> | |
#define BTN_A_PIN 37 | |
#define LED_PIN 10 | |
#define LIGHT_PIN 36 | |
const char *ssid = "Google NestがつながっているWiFiのSSID"; | |
const char *password = "Google NestがつながっているWiFiのパスワード"; | |
GoogleHomeNotifier ghn; | |
const char displayName[] = "Nest"; //Google Home のデバイス名 | |
void googleHomeConnection(String lang_str1, String talk_str1) | |
{ | |
Serial.println("connecting to Google Home..."); | |
if (ghn.device(displayName, lang_str1.c_str()) != true) | |
{ | |
Serial.println(ghn.getLastError()); | |
return; | |
} | |
Serial.print("found Google Home("); | |
Serial.print(ghn.getIPAddress()); | |
Serial.print(":"); | |
Serial.print(ghn.getPort()); | |
Serial.println(")"); | |
if (ghn.notify(talk_str1.c_str()) != true) | |
{ | |
Serial.println(ghn.getLastError()); | |
return; | |
} | |
Serial.println("Done."); | |
} | |
void setup() | |
{ | |
// initialize the M5Stack object | |
M5.begin(); | |
Serial.begin(9600); | |
// Lcd display | |
M5.Lcd.println("ESP32/ESP8266 google-home-notifier Test"); | |
pinMode(LED_PIN, OUTPUT); | |
pinMode(LIGHT_PIN, INPUT); | |
Serial.println(""); | |
Serial.print("connecting to Wi-Fi"); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) | |
{ | |
delay(250); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("connected."); | |
Serial.print("IP address: "); | |
Serial.println(WiFi.localIP()); //Print the local IP | |
} | |
void loop() | |
{ | |
// 画面塗りつぶし | |
M5.Lcd.fillScreen(BLACK); | |
// 光センサの値 | |
int val = 0; | |
val = analogRead(LIGHT_PIN); | |
M5.Lcd.setCursor(0, 0, 2); | |
M5.Lcd.println(val); | |
delay(100); | |
if (val > 4000) //センサーの様子を見て調整 | |
{ | |
digitalWrite(LED_PIN, LOW); | |
} | |
M5.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment