|
| 1 | +# SPDX-FileCopyrightText: 2018 Anne Barela for Adafruit Industries |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +import time |
| 6 | +import board |
| 7 | +from analogio import AnalogIn |
| 8 | +from adafruit_crickit import crickit |
| 9 | +import neopixel |
| 10 | + |
| 11 | +print("Peltier Module Demo") |
| 12 | + |
| 13 | +pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False) |
| 14 | + |
| 15 | +def show_value(time_val): # Show time on NeoPixels on CPX |
| 16 | + num_pixels = int(10-time_val) |
| 17 | + for i in range(num_pixels): |
| 18 | + pixels[i] = (10*(i+1), 0, 0) |
| 19 | + for i in range(num_pixels, 10): |
| 20 | + pixels[i] = (0, 0, 0) |
| 21 | + pixels.show() |
| 22 | + |
| 23 | +TMP36 = AnalogIn(board.A3) # TMP36 connected to A3, power & ground |
| 24 | +POT = AnalogIn(board.A7) # potentiometer connected to A7, power & ground |
| 25 | + |
| 26 | +peltier = crickit.dc_motor_2 # Drive the Peltier from Motor 2 Output |
| 27 | + |
| 28 | +while True: # Loop forever |
| 29 | + |
| 30 | + voltage = TMP36.value * 3.3 / 65536.0 |
| 31 | + tempC = (voltage - 0.5) * 100.0 |
| 32 | + tempF = (tempC * 9.0 / 5.0) + 32.0 |
| 33 | + |
| 34 | + cool_value = POT.value / 6553.6 # convert 0.0 to 10.0 |
| 35 | + |
| 36 | + # timing can be zero or can be 1 second to 10 seconds |
| 37 | + # between 0 and 1 is too short a time for a Peltier module |
| 38 | + if cool_value < 0.2: |
| 39 | + cool_value = 0.0 |
| 40 | + if 1.0 > cool_value >= 0.2: |
| 41 | + cool_value = 1.0 |
| 42 | + |
| 43 | + print((tempF, cool_value)) # Show in REPL |
| 44 | + show_value(cool_value) # Show on NeoPixels |
| 45 | + |
| 46 | + # Peltier cannot be PWM - either off or on |
| 47 | + # Use potentiometer read to set seconds b |
| 48 | + if cool_value > 0: |
| 49 | + peltier.throttle = 0.0 # turn off |
| 50 | + time.sleep(cool_value) # wait |
| 51 | + |
| 52 | + peltier.throttle = 1.0 # turn on |
| 53 | + time.sleep(10.0 - cool_value) # wait |
0 commit comments