Skip to content

Commit 8b5e9a3

Browse files
authored
Fixup digital in
1 parent 38902fe commit 8b5e9a3

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"""
22
'adafruitio_06_digital_in.py'
33
==================================
4-
Example of sending GPS data points
5-
to an Adafruit IO Feed using the API
4+
Example of sending button values
5+
to an Adafruit IO feed.
66
77
Author(s): Brent Rubell, Todd Treece
88
"""
@@ -11,37 +11,43 @@
1111

1212
# import Adafruit Blinka
1313
from digitalio import DigitalInOut, Direction, Pull
14-
from board import *
14+
import digitalio
15+
import board
1516

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

1920
# Set to your Adafruit IO key.
20-
ADAFRUIT_IO_USERNAME = 'user'
21-
ADAFRUIT_IO_KEY = 'key
22-
'
21+
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
22+
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'
2323

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

27-
try:
27+
try: # if we have a 'digital' feed
2828
digital = aio.feeds('digital')
29-
except RequestError:
29+
except RequestError: # create a digital feed
3030
feed = Feed(name="digital")
3131
digital = aio.create_feed(feed)
3232

3333
# button set up
34-
button = digitalio.DigitalInOut(board.D5)
34+
button = digitalio.DigitalInOut(board.D12)
3535
button.direction = Direction.INPUT
36-
button.pull = Pull.UP
36+
button.pull = Pull.DOWN
37+
38+
button_current = 0
39+
button_last = 0
3740

3841
while True:
39-
if button.value:
40-
print('ON, sending button...\n')
41-
aio.send(digital.key, 0)
42+
if not button.value:
43+
button_current = True
4244
else:
43-
print('OFF, sending button..\n')
44-
aio.send(digital.key, 1)
45-
45+
button_current = False
46+
47+
print('Sending Value to IO: ', button_current)
48+
aio.send(digital.key, button_current)
49+
50+
# store the button state
51+
button_last = button_current
4652
# avoid timeout from adafruit io
47-
time.sleep(0.01)
53+
time.sleep(1.5)

0 commit comments

Comments
 (0)