Update cold.py
use cpx analog inputs
import time
-from adafruit_crickit import crickit
import board
+from analogio import AnalogIn
+from adafruit_crickit import crickit
import neopixel
print("Peltier Module Demo")
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
-def show_value(time_val):
+def show_value(time_val): # Show time on NeoPixels on CPX
num_pixels = int(10-time_val)
for i in range(num_pixels):
pixels[i] = (10*(i+1), 0, 0)
@@ -16,20 +17,18 @@ def show_value(time_val):
pixels.show()
return
-# For signal control, we'll chat directly with seesaw
-ss = crickit.seesaw
-TMP36 = crickit.SIGNAL1 # TMP36 connected to signal port 1 & ground
-POT = crickit.SIGNAL8 # potentiometer connected to signal port 8 & ground
+TMP36 = AnalogIn(board.A3) # TMP36 connected to A3, power & ground
+POT = AnalogIn(board.A7) # potentiometer connected to A7, power & ground
peltier = crickit.dc_motor_2 # Drive the Peltier from Motor 2 Output
-while True:
+while True: # Loop forever
- voltage = ss.analog_read(TMP36) * 3.3 / 1024.0
+ voltage = TMP36.value * 3.3 / 65536.0
tempC = (voltage - 0.5) * 100.0
tempF = (tempC * 9.0 / 5.0) + 32.0
- cool_value = ss.analog_read(POT) / 102.30 # convert 0.0 to 10.0
+ cool_value = POT.value / 6553.6 # convert 0.0 to 10.0
# timing can be zero or can be 1 second to 10 seconds
# between 0 and 1 is too short a time for a Peltier module
@@ -38,8 +37,8 @@ while True:
if cool_value >= 0.2 and cool_value < 1.0:
cool_value = 1.0
- print((tempF, cool_value))
- show_value(cool_value)
+ print((tempF, cool_value)) # Show in REPL
+ show_value(cool_value) # Show on NeoPixels
# Peltier cannot be PWM - either off or on
# Use potentiometer read to set seconds b
