a circuit playground express wizard staff

wzrd_util.py 821B

12345678910111213141516171819202122232425262728
  1. # Some utility functions.
  2. def get_color_for_temp(temp_current):
  3. # i can't think in degrees celsius to save my life
  4. temp_cold = 5
  5. temp_comfort = 27
  6. temp_hot = 46
  7. temp_range = temp_hot - temp_cold
  8. if temp_current >= temp_hot:
  9. return (80, 0, 0)
  10. elif temp_current <= temp_cold:
  11. return (0, 0, 80)
  12. else:
  13. return get_color_in_range(temp_cold, temp_hot, temp_current)
  14. def get_color_in_range(minimum, maximum, value):
  15. max_color_val = 30
  16. minimum, maximum = float(minimum), float(maximum)
  17. ratio = 2 * (value - minimum) / (maximum - minimum)
  18. b = int(max(0, max_color_val * (1 - ratio)))
  19. r = int(max(0, max_color_val * (ratio - 1)))
  20. g = max_color_val - b - r
  21. return (r, g, b)
  22. def photocell_value(input):
  23. return input.value * 330 // (2 ** 16)