diff --git a/cds01.ino b/cds01.ino new file mode 100644 index 0000000..4978a15 --- /dev/null +++ b/cds01.ino @@ -0,0 +1,60 @@ +#include +#include +#include + +const char* ssid = "miura2g"; +const char* password = "jikken2022"; + +int PIN = 36; + +// +--- 15kΩ抵抗 --+-- CdSセル --+ +// | | | +// GND G26 3V3 +// https://www.storange.jp/2012/03/arduinocds.html + +// 注意点: https://lang-ship.com/reference/unofficial/M5StickC/Peripherals/ADC/ +int light = 0; +void setup() { + M5.begin(); + Serial.begin(115200); + pinMode(PIN, ANALOG); // PINのモード設定 + // https://lang-ship.com/blog/work/m5stickc-io/ + + WiFi.begin(ssid, password); + while (WiFi.status() != WL_CONNECTED){ + delay(50); + Serial.print("."); + } + + delay(1000); +} + +void loop() { + M5.Beep.update(); + light = analogRead(PIN); + Serial.printf("%04d\n", light ); // 暗 0 〜 4095 明 + if (light < 3000) + { + //digitalWrite(36, 1); + M5.Beep.tone(1000,500); + Serial.printf("HIGH \n"); + + } + + char* weatherapi_url = "https://script.google.com/macros/s/AKfycbzlbfiBTz_WOpS3Vb2quIos3nwVvgbyudq-gSI0-p9TRbWDe9XCXDb5pmBcjg-HH20qGA/exec?light="; + //char buf[weatherapi_url.length()+4]; + char tmp[400]; + snprintf(tmp, 256, "%s%d",weatherapi_url, light); + HTTPClient http; // クライアント作成 + http.begin(tmp); // HTTPでサーバに接続 + int httpCode = http.GET(); // ステータスコードを取得 + if (httpCode > 0) { + Serial.println(httpCode); + if (httpCode == HTTP_CODE_OK) { // ステータスコードが「成功」(200) なら + String payload = http.getString(); + Serial.println(payload); + } + } + http.end(); + delay(10000); +} \ No newline at end of file