Skip to content

Commit 7e20cc8

Browse files
authored
Add files via upload
1 parent c4f235c commit 7e20cc8

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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("Heating Pad Demo")
12+
13+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, auto_write=False)
14+
15+
def show_value(heat_val): # Show throttle on NeoPixels on CPX
16+
num_pixels = int(10 * (heat_val + 0.002))
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+
heating_pad = crickit.dc_motor_2 # Set the motor object to heating pad
27+
28+
while True: # Loop Forever
29+
30+
voltage = TMP36.value * 3.3 / 65536.0 # Read temp sensor, get voltage
31+
tempC = (voltage - 0.5) * 100.0 # Calculate Celsius
32+
tempF = (tempC * 9.0 / 5.0) + 32.0 # Calculate Fahrenheit
33+
34+
heat_value = POT.value / 65536.0 # Value (0.0 to 1.0) to drive pad
35+
36+
print((tempF, heat_value)) # Display temperature and drive
37+
show_value(heat_value)
38+
39+
heating_pad.throttle = heat_value # set Motor throttle value to heat_value
40+
41+
time.sleep(0.25) # Wait a bit before checking all again

0 commit comments

Comments
 (0)