Created
January 25, 2026 06:40
-
-
Save vestige/59a1313d6194007492839ae138b0f8ff 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
| from machine import Pin | |
| import time | |
| # グローバル変数を定義(割り込みフラグ) | |
| touch_detected = False | |
| # 割り込みハンドラ関数 | |
| def touch_handler(pin): | |
| global touch_detected | |
| print("タッチを検知") # 直接ここで反応を表示 | |
| touch_detected = True # 割り込みフラグをTrueに設定 | |
| # 静電容量タッチセンサーを接続しているピンを設定 | |
| touch_sensor = Pin(28, Pin.IN) | |
| # タッチセンサーの割り込み設定 | |
| touch_sensor.irq(trigger=Pin.IRQ_RISING, handler=touch_handler) | |
| counter = 0 # カウンター変数 | |
| while True: | |
| counter += 1 # カウンターに1を加算 | |
| print(counter) # 現在のカウンター値を出力 | |
| print("スリープを開始") | |
| time.sleep(10) | |
| print("スリープから復帰") | |
| if touch_detected: | |
| touch_detected = False # 割り込みフラグをリセット |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment