Skip to content

Commit 82c4724

Browse files
temp sensor
1 parent 7a7a689 commit 82c4724

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

dht_temp_humidity.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#Import ElectroBlocks library
2+
from electroblocks import ElectroBlocks
3+
import time # imports the time library
4+
5+
6+
# Variable Declaration
7+
8+
9+
# Initialise the program settings and configurations
10+
11+
eb = ElectroBlocks() # Create an instance of the ElectroBlocks class
12+
eb.config_dht_temp(4, "DHT11")
13+
14+
for _ in range(1, 4):
15+
temp = eb.dht_temp_celcius()
16+
humidity = eb.dht_temp_humidity()
17+
print(f"Temp: {temp} & Humidity: {humidity}")
18+
time.sleep(1)
19+
20+
21+
print("COMPLETE")

electroblocks/core.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ComponentPins(Enum):
2121
DIGITAL_READ = 14
2222
JOYSTICK = 16
2323
ULTRASONIC_SENSOR = 17
24-
RFID = 18
24+
RFID = 18,
25+
TEMP = 19,
2526

2627
class ElectroBlocks:
2728

@@ -156,19 +157,35 @@ def config_joystick(self, x, y, sw):
156157

157158
def joystick_angle(self):
158159
pin = self.pins[ComponentPins.JOYSTICK][0]
159-
[pressed, angle, engaged] = self._find_sensor_str(pin, "js")
160+
[pressed, angle, engaged] = self._find_sensor_str(pin, "js").split('-')
160161
return angle
161162

162163
def is_joystick_button_pressed(self):
163164
pin = self.pins[ComponentPins.JOYSTICK][0]
164-
[pressed, angle, engaged] = self._find_sensor_str(pin, "js")
165+
[pressed, angle, engaged] = self._find_sensor_str(pin, "js").split('-')
165166
return pressed
166167

167168
def is_joystick_engaged(self):
168169
pin = self.pins[ComponentPins.JOYSTICK][0]
169-
[pressed, angle, engaged] = self._find_sensor_str(pin, "js")
170+
[pressed, angle, engaged] = self._find_sensor_str(pin, "js").split('-')
170171
return pressed
171172

173+
# Temp
174+
def config_dht_temp(self, pin, type):
175+
tempType = "1" if type == "DHT11" else "2"
176+
self._send(f"register::dht::{pin}::{tempType}")
177+
self._add_pin(ComponentPins.TEMP, pin)
178+
179+
def dht_temp_celcius(self):
180+
pin = self.pins[ComponentPins.TEMP][0]
181+
[humidity, temp] = self._find_sensor_str(pin, "dht").split('-')
182+
return temp
183+
184+
def dht_temp_humidity(self):
185+
pin = self.pins[ComponentPins.TEMP][0]
186+
[humidity, temp] = self._find_sensor_str(pin, "dht").split('-')
187+
return humidity
188+
172189

173190
#IR Remote
174191

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "electroblocks"
7-
version = "0.1.13"
7+
version = "0.1.14"
88
description = "Python client library to interact with ElectroBlocks Arduino firmware"
99
authors = [
1010
{ name = "Noah Glaser", email = "glaserpower@gmail.com" }
File renamed without changes.

0 commit comments

Comments
 (0)