Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- import sys
- import time
- import pigpio
- import logging
- import datetime
- import subprocess
- logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(asctime)s - %(message)s',)
- def do_watcher():
- pi = pigpio.pi('pigpiod', 8888)
- if not pi.connected:
- exit()
- debounce = 1000
- pi.set_mode(18, pigpio.INPUT)
- pi.set_glitch_filter(18, debounce)
- cb1 = pi.callback(18, pigpio.RISING_EDGE, button_main)
- logging.info("PiGPIO Conected");
- try:
- while True:
- time.sleep(1)
- except KeyboardInterrupt:
- cb1.cancel()
- def button_main(gpio, level, tick):
- """CALLBACK: Respond when the main button is pressed """
- logging.info("button main pressed")
- subprocess.call("/webhook.sh ", shell=True)
- if __name__ == "__main__":
- logging.info ("Starting button watcher");
- do_watcher()
Advertisement
Add Comment
Please, Sign In to add comment