'output pin assignments symbol speaker = 7 'sound output symbol sugar = 6 'sugar motor controller symbol motor = 5 'stirs tea symbol element = 4 'turns on/off the heating element symbol errorbask = 3 'error led for basket and cup symbol errorwet = 2 'error led for water overflow symbol timedisp = 1 'activates binary counter for time display on 7 segment symbol sugardisp = 0 'activates binary counter for sugar display on 7 segment 'input pin assignments symbol wet = pin0 'checks to make sure water overflow does not occur symbol cup = pin1 'checks to make sure cup is in place and starts brewing process symbol basket = pin2 'checks to make sure basket is in place symbol timebutton = pin3 'use to increase/decrease brewtime symbol sugarbutton = pin4 'use to increase/decrease amount of sugar 'input pin assigned for output!!! symbol armup = 5 'moving stick up to dispense tea symbol armdown = 6 'moving stick down to stop dispensing and lower arm into teacup 'analog input pin assignment symbol temp = 0 'variables used in program symbol brewtime = b10 '8 bit number for brewtime symbol draintime = w0 '8 bit number for draintime symbol loopa = b11 '8 bit number for use in loops symbol loopb = b12 '8 bit number for first nested loop symbol starttime = w1 '16 bit number for time between element on and drip start symbol tspdisp = w2 '16 bit number for milliseconds it takes to dispense 1 tsp of sugar symbol sugartime = w3 '16 bit number for sugartime symbol temperature = b13 '8 bit number representing temperature symbol safetemp = b14 '8 bit number representing safe drinking temperature symbol armtime = w4 '8 bit number representing time it takes the arm to move up or down main: 'declaring values for our variables let brewtime = 1 let sugartime = 0 let draintime = 35000 let armtime = 1000 let tspdisp = 100 let safetemp = 100 for loopa = 1 to 9 step 1 gosub incsugar next loopa do while cup = 0 if timebutton = 1 then if brewtime < 9 then let brewtime = brewtime + 1 gosub inctime pause 500 else let brewtime = 1 gosub inctime gosub inctime pause 500 endif endif if sugarbutton = 1 then if sugartime < 4 then let sugartime = sugartime + 1 gosub incsugar pause 500 else let sugartime = 0 for loopa = 1 to 6 gosub incsugar next loopa pause 500 endif endif loop gosub checkwet 'checks to make sure there is less than the maximum amount of water that the basket can hold gosub checkall 'checks cup and basket sensors, turns on element if all is ok 'This subtracts the sugar dispense time from starttime to get a consistent 30 seconds between element start and driptime let starttime = tspdisp * sugartime let starttime = 30000 - starttime let starttime = starttime + 100 do while starttime > 100 let starttime = starttime - 100 gosub checkall pause 100 loop 'begins to dispense sugar and pauses for right amount to come out if sugartime > 0 then high sugar for loopa = 1 to sugartime step 1 pause tspdisp 'time it takes for one tsp of sugar to dispense in ms next loopa low sugar endif gosub checkall 'nested loop checks to make sure everything is ok while brewing is processing for loopa = 1 to 60 step 1 for loopb = 1 to 100 step 1 pause brewtime gosub checkall next loopb next loopa low element high portc armup low portc armdown pause draintime low portc armup high portc armdown pause armtime 'time it takes to get stick to inside cup low portc armdown high motor wait 30 readadc temp, temperature 'continues to read temperature as motor stirs, checking for safe temperature do while temperature > safetemp readadc temp, temperature loop low motor high portc armup pause armtime 'time it takes to get arm up low portc armup for loopa = 1 to 3 step 1 'signals with 3 beeps that tea is ready sound speaker,(80,500) low speaker pause 500 next loopa end 'sets microcontroller to sleep mode until powercycled checkall: 'runs checkbasket and checkcup, will pause and turn off element if error, turns on/leaves on element if all is ok gosub checkbasket gosub checkcup high element return checkbasket: 'checks to make sure basket is present, if not, stops program and turns of element, flashing basket/cup error button if basket = 0 then low element do while basket = 0 high errorbask pause 250 low errorbask pause 250 loop endif return checkcup: 'checks to make sure cup is present, if not, stops program and turns of element, flashing basket/cup error button if cup = 0 then low element do while cup = 0 high errorbask pause 250 low errorbask pause 250 loop endif return checkwet: 'checks to see if reservoir is overfilled for the basket, if it is, the water level led will flash, and then program ends. (must powercycle) if wet = 1 then do while wet = 1 high errorwet pause 250 low errorwet pause 250 loop end endif return incsugar: 'increases binary counter for sugar time display high sugardisp pause 1 low sugardisp pause 1 return inctime: 'increases binary counter for brew time display high timedisp pause 1 low timedisp pause 1 return