From 77f939e10c8261c9630e459dfdcf17a0790270b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yannik=20Sch=C3=A4dler?= Date: Tue, 5 Dec 2017 21:33:37 +0100 Subject: [PATCH] add: jsonkram --- json2.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 json2.py diff --git a/json2.py b/json2.py new file mode 100644 index 0000000..b5843b0 --- /dev/null +++ b/json2.py @@ -0,0 +1,44 @@ +import json +import time +import RPi.GPIO as GPIO +pin_number = 18; + +data = {1:"asdf"} +wert_des_schalters = False + +while True: + time.sleep(10) # Anzahl der sekunden, die gewartet wird + + GPIO.setmode(GPIO.BCM) + GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) + wert_des_schalters = GPIO.input(18) + + + if wert_des_schalters == False: + data = {1: wert_des_schalters} + with open('data.txt', 'w') as outfile: + json.dump(data, outfile) + + if wert_des_schalters == True: + data = {1: wert_des_schalters} + with open('data.txt', 'w') as outfile: + json.dump(data, outfile) + + +#/* Sphinx Vorschlag */ +''' + + GPIO.setmode(GPIO.BCM) + GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) + + while true: + sleep(10); + + if wert_des_schalters != GPIO:Input(pin_number) # das ist gut + sleep(1); // Contact bounce protection + wert_des_schalters = GPIO.Input(pin_number) + data = {1:wert_des_schalters} + with open('data.txt', 'w') as outfile: + json.dump(data, outfile) + +'''