Created
April 1, 2020 01:22
-
-
Save TakehikoShimojima/819bfc07d40a225e3bbf9d27a96a76cc to your computer and use it in GitHub Desktop.
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 <WiFi.h> | |
#include <Ambient.h> | |
#define PIR 36 | |
const char* ssid = "ssid"; // この場所のSSID(2.4GHzの) | |
const char* password = "password"; // SSIDに対応するパスワード | |
unsigned int channelId = 100; | |
const char* writeKey = "writeKey"; | |
WiFiClient client; | |
Ambient am; // Ambientオブジェクトを作る | |
void setup() { | |
M5.begin(); | |
M5.Lcd.fillScreen(BLACK); // 背景を黒にする | |
pinMode(PIR, INPUT_PULLUP); | |
WiFi.begin(ssid, password); // Wi-Fi APに接続する | |
while (WiFi.status() != WL_CONNECTED) { // Wi-Fi AP接続待ち | |
delay(500); | |
M5.Lcd.print('.'); | |
} | |
M5.Lcd.print("\r\nWiFi connected\r\nIP address: "); | |
M5.Lcd.println(WiFi.localIP()); // このM5Stackに割り当てられたIPアドレス | |
delay(2000); | |
M5.Lcd.fillScreen(BLACK); // 背景を黒にする | |
M5.Lcd.setTextSize(3); // 文字サイズを3にする | |
am.begin(channelId, writeKey, &client); | |
} | |
bool pir = 0; // 前のPIRセンサの値 | |
void loop() { | |
bool p = digitalRead(PIR); // 今のPIRセンサの値を読む | |
M5.Lcd.setCursor(10, 10); | |
M5.Lcd.print(p); | |
if (pir != p) { // pirが0、pが1 または pirが1、pが0なら | |
pir = p; | |
am.set(1, pir); | |
am.send(); | |
} | |
delay(5 * 1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment