Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save karakuri-musha/97725beda59271b9964e3a4c94ede224 to your computer and use it in GitHub Desktop.
Save karakuri-musha/97725beda59271b9964e3a4c94ede224 to your computer and use it in GitHub Desktop.
#include <M5Core2.h> // M5Stack Core 2 用のライブラリ
#define SENSOR_PIN 19 // 人感センサーからのフィードバック受信用GPIO
int stat_s = 0; // 検知フラグ
int change_s = 0; // ステータスの変更フラグ
void Sensor_Callback(){ // 割込み時の処理関数
stat_s = 1; // ステータスを1(検知)へ変更
}
void setup() {
M5.begin(); // M5Stack初期化
Serial.begin(115200); // シリアル接続の開始
delay(500); // 待ち
pinMode(SENSOR_PIN, INPUT_PULLDOWN); // センサー値を入力するピンのモード設定
stat_s = 0; // ステータスを0(無検知)へ設定
attachInterrupt(SENSOR_PIN, Sensor_Callback, RISING); // 割込み処理を定義(G19電圧が0から3.3Vに変化:上昇)した場合に関数を実行
M5.Lcd.setCursor(10,120); // ディスプレイ表示用
M5.Lcd.setTextFont(1);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.println("Watching Now!");
}
void loop() {
if (stat_s == 1) { // ステータスが検知になった場合の処理
M5.Lcd.fillScreen(BLACK); // ディスプレイ表示用
M5.Lcd.fillCircle(160, 120, 30, RED);
M5.Lcd.fillCircle(160, 120, 20, BLACK);
delay(500);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.fillCircle(160, 120, 60, RED);
M5.Lcd.fillCircle(160, 120, 50, BLACK);
delay(500);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.fillCircle(160, 120, 90, RED);
M5.Lcd.fillCircle(160, 120, 80, BLACK);
delay(1000);
stat_s = 0; // ステータスを0:無検知へ変更
change_s = 1; // ステータスの変更フラグを1へ変更
}
else {
if (change_s == 1) { // 無検知状態でステータス変更フラグが1の場合
M5.Lcd.fillScreen(BLACK); // ディスプレイ表示用
M5.Lcd.setCursor(10,120);
M5.Lcd.setTextFont(1);
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.setTextSize(3);
M5.Lcd.println("Watching Now!");
change_s = 0; // ステータスの変更フラグを0へ変更
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment