5
5
import time
6
6
import random
7
7
import board
8
- from digitalio import DigitalInOut , Direction , Pull
9
8
import adafruit_dps310
10
9
import adafruit_ahtx0
11
10
from adafruit_funhouse import FunHouse
12
11
13
- funhouse = FunHouse (
14
- default_bg = 0x0F0F00 ,
15
- scale = 2 ,
16
- )
17
-
18
12
i2c = board .I2C ()
19
13
dps310 = adafruit_dps310 .DPS310 (i2c )
20
14
aht20 = adafruit_ahtx0 .AHTx0 (i2c )
21
15
22
- def random_color ():
23
- return random .randrange (0 , 7 ) * 32
16
+ funhouse = FunHouse (
17
+ default_bg = 0x0F0F00 ,
18
+ scale = 2 ,
19
+ )
24
20
25
21
funhouse .peripherals .set_dotstars (0x800000 , 0x808000 , 0x008000 , 0x000080 , 0x800080 )
26
22
27
- # sensor setup
28
- sensors = []
29
- for p in (board .A0 , board .A1 , board .A2 ):
30
- sensor = DigitalInOut (p )
31
- sensor .direction = Direction .INPUT
32
- sensor .pull = Pull .DOWN
33
- sensors .append (sensor )
34
-
35
- def set_label_color (conditional , index , on_color ):
36
- if conditional :
37
- funhouse .set_text_color (on_color , index )
38
- else :
39
- funhouse .set_text_color (0x606060 , index )
40
-
41
- # Create the labels
42
- funhouse .display .show (None )
43
- slider_label = funhouse .add_text (text = "Slider:" , text_position = (50 , 30 ), text_color = 0x606060 )
44
- capright_label = funhouse .add_text (text = "Touch" , text_position = (85 , 10 ), text_color = 0x606060 )
45
- pir_label = funhouse .add_text (text = "PIR" , text_position = (60 , 10 ), text_color = 0x606060 )
46
- capleft_label = funhouse .add_text (text = "Touch" , text_position = (25 , 10 ), text_color = 0x606060 )
47
- onoff_label = funhouse .add_text (text = "OFF" , text_position = (10 , 25 ), text_color = 0x606060 )
48
- up_label = funhouse .add_text (text = "UP" , text_position = (10 , 10 ), text_color = 0x606060 )
49
- sel_label = funhouse .add_text (text = "SEL" , text_position = (10 , 60 ), text_color = 0x606060 )
50
- down_label = funhouse .add_text (text = "DOWN" , text_position = (10 , 100 ), text_color = 0x606060 )
51
- jst1_label = funhouse .add_text (text = "SENSOR 1" , text_position = (40 , 80 ), text_color = 0x606060 )
52
- jst2_label = funhouse .add_text (text = "SENSOR 2" , text_position = (40 , 95 ), text_color = 0x606060 )
53
- jst3_label = funhouse .add_text (text = "SENSOR 3" , text_position = (40 , 110 ), text_color = 0x606060 )
54
- temp_label = funhouse .add_text (text = "Temp:" , text_position = (50 , 45 ), text_color = 0xFF00FF )
55
- pres_label = funhouse .add_text (text = "Pres:" , text_position = (50 , 60 ), text_color = 0xFF00FF )
56
- funhouse .display .show (funhouse .splash )
57
-
58
- #pylint: disable=unused-argument
23
+ # pylint: disable=unused-argument
59
24
def connected (client ):
60
25
print ("Connected to Adafruit IO! Subscribing..." )
61
26
client .subscribe ("buzzer" )
62
27
client .subscribe ("neopixels" )
63
28
29
+
64
30
def subscribe (client , userdata , topic , granted_qos ):
65
31
print ("Subscribed to {0} with QOS level {1}" .format (topic , granted_qos ))
66
32
33
+
67
34
def disconnected (client ):
68
35
print ("Disconnected from Adafruit IO!" )
69
36
37
+
70
38
def message (client , feed_id , payload ):
71
39
print ("Feed {0} received new value: {1}" .format (feed_id , payload ))
72
40
if feed_id == "buzzer" :
@@ -77,7 +45,8 @@ def message(client, feed_id, payload):
77
45
color = int (payload [1 :], 16 )
78
46
funhouse .peripherals .dotstars .fill (color )
79
47
80
- #pylint: enable=unused-argument
48
+
49
+ # pylint: enable=unused-argument
81
50
82
51
# Initialize a new MQTT Client object
83
52
funhouse .network .init_io_mqtt ()
@@ -110,21 +79,3 @@ def message(client, feed_id, payload):
110
79
last_pir = funhouse .peripherals .pir_sensor
111
80
funhouse .network .mqtt_publish ("pir" , "%d" % last_pir )
112
81
funhouse .peripherals .led = False
113
-
114
- set_label_color (funhouse .peripherals .captouch6 , onoff_label , 0x00FF00 )
115
- set_label_color (funhouse .peripherals .captouch7 , capleft_label , 0x00FF00 )
116
- set_label_color (funhouse .peripherals .captouch8 , capright_label , 0x00FF00 )
117
-
118
- slider = funhouse .peripherals .slider
119
- if slider is not None :
120
- funhouse .peripherals .dotstars .brightness = slider
121
- funhouse .set_text ("Slider: %1.1f" % slider , slider_label )
122
- set_label_color (slider is not None , slider_label , 0xFFFF00 )
123
-
124
- set_label_color (funhouse .peripherals .button_up , up_label , 0xFF0000 )
125
- set_label_color (funhouse .peripherals .button_sel , sel_label , 0xFFFF00 )
126
- set_label_color (funhouse .peripherals .button_down , down_label , 0x00FF00 )
127
- set_label_color (funhouse .peripherals .pir_sensor , pir_label , 0xFF0000 )
128
- set_label_color (sensors [0 ].value , jst1_label , 0xFFFFFF )
129
- set_label_color (sensors [1 ].value , jst2_label , 0xFFFFFF )
130
- set_label_color (sensors [2 ].value , jst3_label , 0xFFFFFF )
0 commit comments