"""
'digitalIn.py'
===================================
Example of sending the status of a
switch to the Adafruit IO Python Client
"""
# Import standard python modules
import time
import RPi.GPIO as GPIO

# import Adafruit IO REST client.
from Adafruit_IO import Client, Feed, RequestError

# setup GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(25, GPIO.IN)

# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'

# Create an instance of the REST client.
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

try: # if we have a 'digital' feed
    digital = aio.feeds('switchread-feed')
except RequestError: # create a digital feed
    feed = Feed(name="switchread-feed")
    digital = aio.create_feed(feed)

while True:
    if GPIO.input(25):
        aio.send(digital.key, 0)
    else:
        aio.send(digital.key, 1)

# timeout so we dont flood adafruit-io with requests
    time.sleep(0.5)

