def main(): """Main method This is run from cron. Will keep running until the specified stop time """ logging.info("Starting mLamp Driver") temperature = read_temperature() temp_progress = interpolate_temperature(temperature) color = color_interpolate_map(color_map, temp_progress) logging.info("Temperature is: {}C, final color will be: {}".format(temperature, color)) while True: now = datetime.datetime.now() is_alarm_hour = alarm_start_hour <= now.hour <= alarm_stop_hour is_alarm_minute = alarm_start_minute <= now.minute <= alarm_stop_minute if is_alarm_hour and is_alarm_minute: time_progress = current_time() / alarm_length() final_color = color_interpolate_fade_in(color, time_progress) logging.debug("Setting color to: {}".format(final_color)) lamp_set_color(final_color) sleep(10) elif now.hour > alarm_stop_hour and now.minute > alarm_stop_minute: # don't forget to turn the lamps off when the time comes lamp_set_color((0, 0, 0)) break else: sleep(60) logging.info("Stopping mLamp Driver")
color_map = {0.0: (255, 0, 0), 0.2: (255, 255, 255), 0.5: (255, 255, 255), 0.8: (0, 200, 255), 1.0: (0, 0, 255)} def nothing(x): pass cv2.namedWindow("Test") cv2.createTrackbar("Temp", "Test", 0, 45, nothing) image = np.zeros((500, 500, 3), dtype=np.uint8) while True: image[:, :, :] = 0 image[:, :, 1] = 255 k = cv2.waitKey(1) & 0xFF if k == 27: break temp = cv2.getTrackbarPos("Temp", "Test") color = color_interpolate_map(color_map, temp / 45) image[:, :] = color temp -= 10 cv2.putText(image, "Temp: " + str(temp) + "C", (20, 20), cv2.FONT_HERSHEY_PLAIN, 1.5, (0, 0, 0)) cv2.imshow("Test", image)