File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,8 @@ class ComponentPins(Enum):
2323 ULTRASONIC_SENSOR = 17
2424 RFID = 18 ,
2525 TEMP = 19 ,
26+ THERMISTOR = 20
27+
2628
2729class ElectroBlocks :
2830
@@ -186,6 +188,23 @@ def dht_temp_humidity(self):
186188 [humidity , temp ] = self ._find_sensor_str (pin , "dht" ).split ('-' )
187189 return humidity
188190
191+ # Thermistor
192+
193+ def config_thermistor (self , pin ):
194+ self ._send (f"register::th::{ pin } " )
195+ self ._add_pin (ComponentPins .THERMISTOR , pin )
196+
197+ def thermistor_celsius (self ):
198+ pin = self .pins [ComponentPins .THERMISTOR ][0 ]
199+ return self ._find_sensor_str (pin , "th" )
200+
201+ def thermistor_fahrenheit (self ):
202+ pin = self .pins [ComponentPins .THERMISTOR ][0 ]
203+ temp = self ._find_sensor_str (pin , "th" )
204+ if (temp == '' ):
205+ return ''
206+ else :
207+ return 32 + (9 / 5 * float (temp ))
189208
190209 #IR Remote
191210
Original file line number Diff line number Diff line change 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_thermistor ("A0" )
13+
14+ for _ in range (1 , 4 ):
15+ celcius = eb .thermistor_celsius ()
16+ fahrenheit = eb .thermistor_fahrenheit ()
17+ print (f'Celcius: { celcius } Fahrenheit: { fahrenheit } ' )
18+ time .sleep (1 )
You can’t perform that action at this time.
0 commit comments