From 6b2fd33c03aeae517512e5150a688fd6fd03f9d0 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Thu, 16 Jul 2020 21:20:38 -0400 Subject: [PATCH] started --- rpitx.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 rpitx.py diff --git a/rpitx.py b/rpitx.py new file mode 100644 index 00000000..1cadee16 --- /dev/null +++ b/rpitx.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +import RPi.GPIO as GPIO +import subprocess +import time +import os + +GPIO.setmode(GPIO.BCM) +GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP) +GPIO.setup(12, GPIO.IN, pull_up_down=GPIO.PUD_UP) +if GPIO.input(12) == False: + powerPin = 16 +else: + powerPin = 17 +GPIO.setwarnings(False) +GPIO.setup(powerPin, GPIO.OUT) +GPIO.output(powerPin, 1); + +while (True): + time.sleep(1) + GPIO.wait_for_edge(26, GPIO.FALLING) + + done = False; + time.sleep(1) + if GPIO.input(26): + print("sudo reboot -h now") + GPIO.setwarnings(False) + GPIO.setup(powerPin, GPIO.OUT) + GPIO.output(powerPin, 0); + subprocess.call(['reboot', '-h', 'now'], shell=False) + GPIO.output(powerPin, 0);