This file contains 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 <M5Stack.h> | |
#include <WiFi.h> | |
#include <WiFiClient.h> | |
WiFiClient client; | |
// WiFi設定 | |
const char* ssid = "*****"; | |
const char* password = "*****"; | |
// IFTTT設定 | |
String event = "*****"; | |
String Secretkey = "*****"; | |
// LEDを接続するピン | |
const int ledPin = 22; | |
// TOTOウォシュレットの流す赤外線信号データ設定 | |
//お尻 | |
unsigned int data_oshiri[] = {604,290,66,45,64,162,64,45,72,40,69,44,67,45,64,45,72,42,67,45,67,45,72,37,69,154,64,50,64,45,66,45,66,45,69,45,64,47,67,43,66,45,66,47,67,44,62,48,64,48,66,159,64,157,71,40,69,46,64,45,64,48,66,45,64,50,64,157,64,159,64,50,64,45,66,45,64,48,69,45,67,4045,603,294,64,45,66,159,67,44,64,47,64,45,66,47,64,45,66,47,62,48,64,48,64,48,64,162,72,37,72,40,69,44,67,45,62,48,66,45,66,45,64,50,64,45,64,48,66,45,64,50,64,157,66,157,64,50,64,45,64,48,64,50,66,45,64,45,66,159,64,159,64,45,66,45,64,48,69,45,64,45,66,4079,606,290,66,47,67,156,62,48,64,48,64,48,66,47,64,47,64,45,64,48,69,45,67,44,64,157,63,48,64,50,64,45,66,45,66,45,69,45,64,47,64,45,66,47,67,45,67,45,67,43,64,159,64,162,72,37,66,45,66,47,67,45,64,45,66,45,66,159,64,157,71,40,66,47,67,45,62,47,64,48,66,4081,604,290,64,50,64,157,66,47,64,47,67,45,64,45,69,45,64,45,66,47,62,48,64,47,66,159,67,45,64,45,66,45,69,44,64,157,64,48,64,48,64,162,72,37,64,159,64,50,64,157,72,42,67,44,67,43,64,48,66,45,67,45,66,47,62,159,66,159,64,47,64,45,64,162,61,50,64,157,69,45,64,3579,603,290,69,44,67,154,64,48,61,50,66,47,61,48,66,45,66,45,69,45,64,47,67,43,66,157,66,45,64,47,64,48,61,50,64,161,64,45,64,50,69,152,66,45,64,159,69,45,67,154,64,48,61,50,64,48,64,47,64,48,64,48,69,45,67,154,61,162,64,50,64,45,66,159,64,47,62,159,64,48,64,3635,608,289,62,47,64,162,66,45,64,47,64,45,72,40,69,45,64,47,67,42,69,43,66,47,64,157,64,48,66,45,69,45,64,47,64,157,66,45,66,48,62,161,66,47,64,157,66,45,66,159,64,47,64,47,61,48,66,45,64,50,64,45,64,50,61,162,64,157,64,48,64,50,61,160,69,43,66,159,64,47,62}; | |
//流す | |
unsigned int data_nagasu[] = {601,297,59,50,64,160,69,45,67,45,64,45,64,48,66,48,67,44,59,50,59,53,66,47,62,159,64,48,61,50,61,53,64,45,64,47,64,48,61,53,67,43,66,45,64,48,69,44,67,156,61,48,61,164,67,154,61,51,61,50,64,50,61,48,61,162,61,52,64,157,61,162,61,53,64,45,64,48,61,50,61,3889,601,295,64,48,61,164,59,50,61,50,61,50,61,53,61,48,64,48,61,51,61,53,64,48,61,162,67,45,67,45,64,45,59,53,66,47,67,44,59,50,61,51,61,50,64,50,62,48,64,160,69,45,67,154,61,162,61,51,66,45,64,47,64,48,61,164,59,50,61,162,61,164,64,45,64,50,64,47,62,50,59}; | |
//ストップ | |
unsigned int data_stop[] = {606,290,66,45,66,157,64,50,64,45,66,48,61,48,64,50,64,47,64,47,62,48,69,45,64,157,64,50,64,47,64,47,64,47,62,50,61,50,62,50,62,51,61,48,63,48,66,48,64,46,64,48,66,45,69,45,64,47,64,48,64,45,66,47,67,45,67,43,64,48,69,45,64,47,64,47,67,45,64,47,64,4847,601,292,64,50,64,159,64,47,64,47,64,47,67,43,64,50,64,47,64,47,64,45,64,48,66,159,64,45,66,45,64,48,69,45,67,45,64,45,66,47,64,47,64,47,64,48,64,48,64,47,64,48,62,48,64,50,61,48,63,50,61,48,64,48,63,48,66,48,61,48,64,50,61,48,66,47,64,48,64,48,61,4532,601,294,61,48,64,160,66,45,66,48,67,45,64,47,64,47,64,45,66,48,64,47,64,45,66,157,66,47,64,45,66,45,64,48,66,47,64,48,64,45,66,47,67,45,67,45,64,45,66,45,66,47,67,45,64,45,64,50,64,45,64,50,67,43,66,47,64,48,62,50,64,45,64,50,64,47,61,50,64,45,64,4532,606,289,64,47,64,160,64,45,64,48,63,48,64,50,64,45,66,45,64,50,64,47,64,47,64,157,66,47,62,50,62,47,63,162,64,48,64,157,66,47,64,159,64,45,64,160,69,45,67,157,64,157,64,50,64,157,66,157,66,47,61,162,64,45,66,47,64,159,69,154,61,162,64,45,66,45,69,45,64,47,64,3189,601,293,66,45,64,162,64,47,64,45,64,48,63,48,66,47,64,45,64,50,61,48,64,50,64,157,64,50,64,47,67,45,64,157,66,47,62,162,64,45,71,154,67,45,62,160,63,48,66,159,64,159,61,50,62,159,64,162,67,45,62,160,64,48,63,48,64,162,64,157,66,159,64,45,64,48,66,45,66,48,64,3226,603,290,66,47,64,159,67,45,64,47,65,47,64,47,61,50,64,47,64,47,64,45,64,48,66,159,64,47,64,45,66,47,61,162,62,48,64,160,69,45,64,157,66,48,64,159,64,45,66,157,66,159,62,48,64,162,61,162,67,43,66,157,66,47,64,46,63,160,66,159,64,157,63,50,64,47,64,48,64,45,64}; | |
// 起動から現在の経過時間 | |
unsigned long now; | |
// 待ち開始時間 | |
unsigned long waitStartMicros; | |
void setup(void) { | |
Serial.begin(115200); | |
M5.begin(); | |
M5.Lcd.fillScreen(BLACK); | |
M5.Lcd.setCursor(10, 10); | |
M5.Lcd.setTextColor(WHITE); | |
M5.Lcd.setTextSize(3); | |
M5.Lcd.printf("START"); | |
pinMode(ledPin, OUTPUT); | |
// Start WiFi | |
Serial.println("Connecting to "); | |
Serial.print(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
// WiFi Connected | |
Serial.println("\nWiFi Connected."); | |
M5.Lcd.setCursor(10, 40); | |
M5.Lcd.setTextColor(WHITE); | |
M5.Lcd.setTextSize(3); | |
M5.Lcd.printf("WiFi Connected."); | |
delay(3000); | |
M5.Lcd.setBrightness(50); | |
M5.Lcd.drawJpgFile(SD, "/baba.jpg"); | |
} | |
void loop() { | |
if(M5.BtnA.wasPressed()) { | |
M5.Lcd.drawJpgFile(SD, "/01.jpg"); | |
M5.update(); | |
sendSignal(data_oshiri,sizeof(data_oshiri)/sizeof(data_oshiri[0])); | |
delay(500); | |
sendSignal(data_oshiri,sizeof(data_oshiri)/sizeof(data_oshiri[0])); | |
delay(2500); | |
iftttSend("{\"value1\":\"お尻洗いを始めました。\"}"); | |
} | |
if(M5.BtnB.wasPressed()) { | |
M5.Lcd.drawJpgFile(SD, "/02.jpg"); | |
M5.update(); | |
sendSignal(data_stop,sizeof(data_stop)/sizeof(data_stop[0])); | |
delay(3000); | |
iftttSend("{\"value1\":\"お尻洗いを止めました。\"}"); | |
} | |
if(M5.BtnC.wasPressed()) { | |
M5.Lcd.drawJpgFile(SD, "/03.jpg"); | |
M5.update(); | |
sendSignal(data_nagasu,sizeof(data_nagasu)/sizeof(data_nagasu[0])); | |
delay(3000); | |
iftttSend("{\"value1\":\"水を流しました。\"}"); | |
} | |
M5.Lcd.drawJpgFile(SD, "/baba.jpg"); | |
M5.update(); | |
} | |
/* | |
赤外線信号の送出 | |
*/ | |
void sendSignal(unsigned int *data, int dataSize) { | |
for (int i = 0; i < dataSize; i++) { | |
unsigned long dataLength = data[i] * 10; | |
now = micros(); | |
do { | |
digitalWrite(ledPin, 1 - i % 2); | |
wait(8); | |
digitalWrite(ledPin, 0); | |
wait(7); | |
} while (long(now + dataLength - micros()) > 0); | |
} | |
Serial.println("Send Signal"); | |
} | |
void wait(signed long waitTime) { | |
waitStartMicros = micros(); | |
while (micros() - waitStartMicros < waitTime) {}; | |
} | |
/* | |
IFTTTへの送出 | |
*/ | |
void iftttSend(String message) { | |
if (client.connect("maker.ifttt.com", 80)) { | |
Serial.println("connection"); | |
client.println("POST /trigger/" + event + "/with/key/" + Secretkey + " HTTP/1.1"); | |
client.println("Host: maker.ifttt.com"); | |
client.println("User-Agent: ESP8266/1.0"); | |
client.println("Connection: close"); | |
client.println("Content-Type: application/json"); | |
client.print("Content-Length: "); | |
client.println(message.length()); | |
client.println(); | |
client.println(message); | |
delay(10); | |
Serial.println("OK"); | |
} else { | |
Serial.println("Err"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment