Skip to content

Commit 38902fe

Browse files
author
brentru
committed
adding digitalin example w/blinka
1 parent 7a44604 commit 38902fe

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
'adafruitio_06_digital_in.py'
3+
==================================
4+
Example of sending GPS data points
5+
to an Adafruit IO Feed using the API
6+
7+
Author(s): Brent Rubell, Todd Treece
8+
"""
9+
# import python system libraries
10+
import time
11+
12+
# import Adafruit Blinka
13+
from digitalio import DigitalInOut, Direction, Pull
14+
from board import *
15+
16+
# import Adafruit IO REST client.
17+
from Adafruit_IO import Client, Feed, RequestError
18+
19+
# Set to your Adafruit IO key.
20+
ADAFRUIT_IO_USERNAME = 'user'
21+
ADAFRUIT_IO_KEY = 'key
22+
'
23+
24+
# Create an instance of the REST client.
25+
aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)
26+
27+
try:
28+
digital = aio.feeds('digital')
29+
except RequestError:
30+
feed = Feed(name="digital")
31+
digital = aio.create_feed(feed)
32+
33+
# button set up
34+
button = digitalio.DigitalInOut(board.D5)
35+
button.direction = Direction.INPUT
36+
button.pull = Pull.UP
37+
38+
while True:
39+
if button.value:
40+
print('ON, sending button...\n')
41+
aio.send(digital.key, 0)
42+
else:
43+
print('OFF, sending button..\n')
44+
aio.send(digital.key, 1)
45+
46+
# avoid timeout from adafruit io
47+
time.sleep(0.01)

0 commit comments

Comments
 (0)