# Module Import
import LocoIOT
import time
# Class Instances Creation
loco_iot = LocoIOT.LocoIOT()
msg = LocoIOT.IOT_Codes()
# Initiate Connection to the Microcontroller
loco_iot.connect()
# Enable NTC Thermistor Hardware Configuration
loco_iot.enable(msg.SUBTYPE_NTC)
loco_iot.enable(msg.SUBTYPE_RGB)
# Start Listening for Control/Request Messages
loco_iot.start()
# Read Initial NTC Temperature Data
ntc_dict = loco_iot.getData(msg.SUBTYPE_NTC)
temp_start = ntc_dict['Temperature NTC (C)']
high_temp = temp_start + 3
low_temp = temp_start - 3
# Map an Input Value to a Different Range of Values
def map_to_range( temp_start, in_min, in_max, out_min, out_max ):
if (temp_start > in_max):
temp_start = in_max
elif(temp_start < in_min):
temp_start = in_min
sensor_range = in_max - in_min
new_range = out_max - out_min
new_value = (((temp_start - out_min) * new_range) / temp_start) + out_min
return new_value
# Infinite Loop: Press STOP to end the loop.
while True:
ntc_dict = loco_iot.getData(msg.SUBTYPE_NTC)
temp_now = ntc_dict['Temperature NTC (C)']
if temp_start > temp_now :
led = map_to_range(temp_start, temp_now, high_temp, 0, 255)
loco_iot.setData(msg.SUBTYPE_RGB, [int(0), int(255-led), int(led)])
print(temp_now)
else:
led = map_to_range(temp_start, temp_now, low_temp, 0, 255)
loco_iot.setData(msg.SUBTYPE_RGB, [int(led), int(255-led), int(0)])
print(temp_now)
# Short Arbitrary Delay
time.sleep(0.1)
# Close Connection to the Microcontroller
loco_iot.close()