Beruflich Dokumente
Kultur Dokumente
import u3
import time
import atexit
import math
d = u3.U3()
'''Constants'''
MAX_THRESH = 120 # Overheat temperature in degrees fahrenheit
V_PER_DEG_F = 0.0052 # Configured volts per degree celsius on IR sensor*
AMB_TEMP = 74 # Set as the average ambient temp for table in degrees fahrenheit
AMB_VOLTAGE = 2.1 # Set to be the voltage reading on thermopile at room temp wit
h no object
READ_INTERVAL = 1 # Number of seconds between reads
ON_OVERHEAT = 30 # Number of seconds to power off on an overheat
CLOCK = 4 # 4MHz/Divisor
DIVISOR = 10 # Configure clock
MODE = 3 # 32bit falling edge
REAL_CLOCK = (CLOCK * 1000000) / DIVISOR # Used for RPM calc
'''Fan RPM Detection'''
d.configIO(TimerCounterPinOffset = 6, NumberOfTimersEnabled = 1, FIOAnalog = 48,
EIOAnalog = 3)
d.configTimerClock(CLOCK, DIVISOR) # Set timer clock, divisor
d.getFeedback(u3.Timer0Config(MODE, Value = 0)) # Set timer mode
'''Digital Output functions
FIO3 H-Bridge control wire #1
FIO2 H-Bridge control wire #2
'''
def hot(d):
d.setFIOState(3,0) # FIO3
d.setFIOState(2,1) # FIO2
def cold(d):
d.setFIOState(3,1) # FIO3
d.setFIOState(2,0) # FIO2
def off(d):
d.setFIOState(3,0) # FIO3
d.setFIOState(2,0) # FIO2
Low
High
High
Low
Low
Low
def convert(reading):
"""
Convert a reading from celsius to fahrenheit.
"""
fahrenheit = 1.8 * reading + 32
reading = fahrenheit
return reading
count = 0
while kbhit() == False:
time.sleep(READ_INTERVAL)
atexit.register(off, d)
'''Analog Inputs'''
Temp_Top_In = d.getAIN(4) # AIN4 Temp sensor on top plate
Temp_Bottom_In = d.getAIN(5) # AIN5 Temp sensor on bottom plate
VthermoIR = d.getAIN(9) # EIN1 Voltage reading on the thermopile
hot(d)
elif Tdrink < (AMB_TEMP - 12): # 8 degrees less than ambient
print 'Cold!\n'
cold(d)
else: # IR temp reading ~ equal to ambient
print 'No drink!'
off(d)
elif Auto and Man: # Switch is in Off position
print 'OFF\n'
off(d)
elif Auto and not Man: # Switch is in Manual position
print 'Manual'
'''Hot / Cold Toggle switch operations'''
if not Cold: # Switch is set to hot
print 'Hot!\n'
hot(d)
elif Cold: # Switch is set to hot
print 'Cold!\n'
cold(d)
else: # Something is broken, nothing happens
off(d)
else: # Something is broken, nothing happens
off(d)
"""
* Note: 0.0052 V per degree F based on linear
calibration using a refrigerated beer and a boiling hot coffee mug
"""