-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcutter_v2.py
59 lines (51 loc) · 1.42 KB
/
cutter_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
Modified code from one of the ME-106 labs
"""
# cutter_v2.py
from machine import Pin, ADC
# import machine
import time
PIN_SPEAKER = Pin(21, Pin.OUT)
PIN_CUTTER = Pin(6, Pin.OUT)
PIN_CUTTER.off()
PIN_SPEAKER.off()
def main():
pressure_check = adc_example()
print("Pressure check pass: {}".format(pressure_check))
if(not pressure_check):
return False
print("Cutting in 2 seconds...")
PIN_SPEAKER.on()
time.sleep(1)
PIN_SPEAKER.off()
PIN_CUTTER.on()
time.sleep(0.05)
PIN_CUTTER.off()
time.sleep(1)
print("Done cutting!")
return True
def adc_example():
# pot_read.py
# import machine
# import time
# pot = machine.ADC(27)
# 0 PSI = 0.3 V
# 40 PSI = 1.1 V
# 80 PSI = 1.9 V - 2.1 V?
pot = ADC(27)
min_pressure = 40 # psi
# pot_values = []
voltage_values = []
for i in range(10):
# while(True):
# Or a while loop that waits until canister is pressurized
pot_value = pot.read_u16()
# pot_values.append(pot_value)
volts = pot_value * 3.3 / 65535
voltage_values.append(volts)
# print("Pot value = {}\nEquivalent to {} V\n".format(pot_value, volts))
print("Volts = {0:.3f}".format(volts))
time.sleep(0.1)
voltage_avg = sum(voltage_values) / len(voltage_values)
print("Average voltage = {}".format(voltage_avg))
return (voltage_avg > 1.1 and voltage_avg < 2.1)