1
1
"""
2
2
'adafruitio_06_digital_in.py'
3
3
==================================
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.
6
6
7
7
Author(s): Brent Rubell, Todd Treece
8
8
"""
11
11
12
12
# import Adafruit Blinka
13
13
from digitalio import DigitalInOut , Direction , Pull
14
- from board import *
14
+ import digitalio
15
+ import board
15
16
16
17
# import Adafruit IO REST client.
17
18
from Adafruit_IO import Client , Feed , RequestError
18
19
19
20
# 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'
23
23
24
24
# Create an instance of the REST client.
25
25
aio = Client (ADAFRUIT_IO_USERNAME , ADAFRUIT_IO_KEY )
26
26
27
- try :
27
+ try : # if we have a 'digital' feed
28
28
digital = aio .feeds ('digital' )
29
- except RequestError :
29
+ except RequestError : # create a digital feed
30
30
feed = Feed (name = "digital" )
31
31
digital = aio .create_feed (feed )
32
32
33
33
# button set up
34
- button = digitalio .DigitalInOut (board .D5 )
34
+ button = digitalio .DigitalInOut (board .D12 )
35
35
button .direction = Direction .INPUT
36
- button .pull = Pull .UP
36
+ button .pull = Pull .DOWN
37
+
38
+ button_current = 0
39
+ button_last = 0
37
40
38
41
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
42
44
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
46
52
# avoid timeout from adafruit io
47
- time .sleep (0.01 )
53
+ time .sleep (1.5 )
0 commit comments