'ADDITIONAL INSTALLATION AND USER INFORMATION FOR 'ILTF (Intelligent Low Temperature Forecaster) 'source code ver. 1.40 'INSTALLATION: '(1)MAKE SURE BOTH LIGHT SENSOR,PHOTOTRANSISTOR Q1, AND TEMPERATURE SENSOR(SEN1) 'ARE WATERPROOFED. '(2)FOR ACCURATE READINGS/FORECAST SEN1 SHOULD BE IN A GOOD WEATHER SHELTER 'THIS MEANS DIRECT SUN SHOULDN'T HIT SEN1 AND IT SHOULD BE PROTECTED FROM THE 'NIGHT SKY. IN ADDITION IT SHOULD HAVE GOOD AIR CIRCULATION SINCE YOU WANT 'TO TAKE THE AIR TEMPERATURE AND NOT THE TEMPERATURE OF THE SUN, CLOUDS 'OR OUTER SPACE '(3) Q1 SHOULD BE ABLE TO "SEE" LIGHT SO ILTF CAN DETERMINE SUNRISE AND 'SUNSET TEMPERATURES/TIMES 'INITIAL USE: 'IT IS BEST TO PROGRAM ILTF AND TO FIRST TURN IT ON DURING THE DAY 'ALTERNATIVELY, RESET ILTF THE FIRST DAY YOU PUT IT INTO OPERATION 'WHILE MUCH OF THE DATA USED BY ILTF IS STORED IN EEPROM, A POWER FAILURE ;WILL CAUSE ERRONEOUS FORECASTS--IN CRITICAL APPLICATIONS USE BATTERY BACKUP 'USING IT: 'ASSUMING YOU FIRST TURN ILTF ON DURING DAYLIGHT HOURS, THE FOUR LEDS WILL LIGHT 'BRIEFLY AND THEN THE FORECAST LED WILL FLASH THE VERSION NUMBER OF THE FIRMWARE 'FOR INSTANCE, WITH VER 1.40, THE FORECAST LED WILL BLINK ONCE, THEN PAUSE 'THEN BLINK Four times quickly. 'NEXT, THE DISPLAY WILL SHOW THE PRESENT TEMPERATURE OF SEN1. IF YOU DON'T TOUCH 'MODE BUTTON AND THE TEMPERATURE IS ABOVE 33 (THE DEFAULT WARNING TEMPERATURE) 'THIS IS ALL YOU WILL SEE UNTIL IT GETS DARK. AFTER DARK, ILTF WILL START 'ITS PROCESS OF FORECASTING THE LOW TEMPERATURE. HOWEVER, IT WON'T ISSUE A 'FORECAST UNTIL 30 MINUTES AFTER SUNSET AND ONLY THEN IF THE TEMPERATURE HAS 'STARTED TO DROP. 'ONCE A FORECAST IS ISSUED, THE FORECAST LED WILL LIGHT AT REGULAR 'INTERVALS AND THE DISPLAY WILL SHOW THE FORECASTED LOW TEMPERATURE. THIS 'FORECAST WILL BE CONTINUALLY UPDATED EVERY 10 MINUTES UNTIL SUNRISE. 'WARNING LED WILL LIGHT WHEN EITHER THE FORECAST LOW IS BELOW THE WARNING 'SET TEMPERATURE OR THE PRESENT TEMPERATURE IS BELOW THIS SET TEMPERATURE 'BATTERY OPERATION: 'ILTF CAN BE USED WITH A 9V TO 15V BATTERY, HOWEVER TO EXTEND BATTERY LIFE 'IT SHOULD BE PUT INTO ITS LOW-POWER CONFIGURATION. TO DO THIS PUT POSTION 1 'OF THE DIP SWITCH ON. WHEN IN THE LOW-POWER MODE, THE DISPLAY IS NORMALLY 'OFF. IF YOU PRESS THE UP.DISPLAY SWITCH THE DISPLAY WILL TURN ON FOR '10 SECONDS AND THEN GO OFF 'USING MODE BUTTON 'YOU CAN DISPLAY THE FORECAST TEMPERATURE, MINIMUM TEMP, MAX TEMP AND WARNING 'TEMP BY USING THE MODE SWITCH. TO DO THIS, DEPRESS THE MODE SWITCH UNTIL 'FORECAST LED LIGHTS. THE DISPLAY WILL SHOW THE FORECASTED TEMPERATURE OR 'STATUS/ERROR CODE(SEE MORE ABOUT STATUS/ERROR CODES LATER) 'PRESS THE MODE SWITCH AGAIN AND THE DISPLAY WILL SHOW THE MINIMUM SINCE 'IT WAS LAST CLEARED,TO CLEAR THE MINIMUM PRESS THE DOWN/CLEAR BUTTON 'PRESS THE MODE BUTTON AGAIN TO DISPLAY THE MAXIMUM, MAXIMUM IS CLEARED THE 'SAME WAY. PRESS THE MODE BUTTON AGAIN AND THE DISPLAY WILL START FLASHING 'THE SET WARNING TEMPERATURE(DEFAULT IS 33). USE THE UP AND DOWN BUTTONS 'TO CHANGE THIS WARNING TEMPERATURE.AFTER YOU CHANGE IT PRESS THE MODE BUTTON 'AGAIN TO RETURN TO THE 'NORMAL' MODE 'CAVEATS: 'ILTF USES SINGLE STATION ANALYSIS TO DETERMINE THE LOW TEMEPRATURE 'BECAUSE OF THIS IT CAN'T SEE CLOUDS MOVING IN OR MOVING OUT OR WIND 'SUDDENLY PICKING UP OF SUDDENLY CALMING DOWN. ITS FORECAST IS QUITE ACCURATE 'ON CRITICAL NIGHTS WHICH ARE CALM AND CLEAR ALL NIGHT. ITS ACCURACY IS 'REDUCED WHEN SAY ITS CLOUDY UNTIL MIDNIGHT AND SUDDENLY CLEARS. HERE, EVEN, 'IT IS USEFUL SINCE IT WILL SENSE THE CLEARING SKY AND WITHIN 20 MINUTES 'MAKE AN UPDATED ACCURATE FORECAST 'THERE ARE STATUS/ERROR CODES THAT ARE DISPLAYED IN PLACE OF THE ACTUAL FORECAST 'ANY NUMBER ABOVE 93 IS ASSUMED TO BE A STATUS/ERROR CODE '94 IS A SPECIAL STATUS/ERROR CODE SINCE IT WILL NORMALLY BE DISPLAYED 'FOR AT LEAST 10 MINUTES, 30 MINUTES AFTER SUSNET. BASICALLY, IT IS TELLING 'THE USER TO PREPARE TO VIEW THE FORECASTED LOW TEMPERATURE 'THIS IS THE EXCITING TIME SINCE IT IS THE FIRST FORECAST MADE BY ILTF 'FOR THE NIGHT'S LOW TEMPERATURE '99 indicates its daytime and a forecast can't be made '98 indicates sunset was too soon ago for accurate average forecast '97 CAN INDICATE SEVERAL THINGS (1) TOO SOON AFTER SUNSET BECAUSE THE 'TEMPERATURE 'HASN'T STARTED TO DROP OR (2) THE TEMP IS RISING AND NOT FALLING '96 INDICATES THE TEMPERATURE SHORTLY AFTER SUNSET IS FALLING TOO RAPIDLY '95 INDICATES A POSSIBLE INTERNAL ERROR--AFTER RESET THE TMPSR_AVG VARIABLE '94 starting to calculate--must wait for 60 calculations to take an average 'This 94 indicates the "exciting time"--the time we wait for the first forecast 'IF THE DISPLAY EVER SHOWS 95 SEND US AN EMAIL AT MAGICLANDELECTRONICS@YAHOO.COM 'also let us know if you find any bugs in the code 'IF YOU WAIT YOU MIGHT RECEIVE AN ACCURATE FORECAST 'NOW THE WARNING LED WILL LIGHT IF THE FORECASTED LOW TEMPERATURE IS EQUAL 'TO OR LOWER THAN THE SET WARNING TEMPERATURE OR THE PRESENT TEMPERATURE '*********************** 'NON-DOCUMENTED INFO/MAY CHANGE WITH UPDATES--IF YOU PRESS THE DOWN SWITCH 'WHEN THE DISPLAY ISN'T FLASHING, THE DISPLAY WILL SHOW THE CURRENT NL(NIGHT 'LENGTH) '*********************** 'march 1,2009 'PLEASE BE PATIENT WHEN USING THE MODE SWITCH TO ACCESS/CLEAR MIN, MAX AND SET 'TEMPERATURE--IT MAY TAKE UP TO 10 SECONDS TO GET INTO THE MODE YOU ARE AFTER 'original source code written by Thomas Fox 'caution:this program uses five unused system variables; s_wo,s_w1,s_w2,s_w3,s_w4 'it assumes the low temperature will be reached at sunrise 'ver 1.40 reversed light sensor--low reading light, high reading dark 'ver 1.30 minor update--if temp rising near sunrise, skipped using avg calc 'ver 1.29M added averaging of TMPSR--won't update TMPSR until 60 calc made 'ver 1.28M fixed a typo, added display forecast at reg intervals 'ver 1.27M fixed NL problem due to isolated ext events (e.g.bird on light sensor) 'ver 1.26M added learning ability 'ver 1.25M added rounding off division, added flash forecast LED for ver number 'ver 1.24M hysteresis was added to light sensor routines 'ver 1.23M added optional low power mode,early versions used standard mode 'ver 1.22M changed the 2000 in 1.22M to 1000 because of word/byte limitations 'ver 1.21M got around PICAXE'S integer USE by multiplying and dividing by 2000 'ver 0.9 beta November 11, 2008 'the learning ability relies on the fact that the longer the night the 'colder the low temperature and the fact this is built into the 'equations used. The program stores the calculated minimum (which was 'calculated after three hours or TIMEL=18 and then compares this number with 'actual temp at sunrise. If the actual calc temp is too low then it 'subtracts 30 min (3 from nl) AND VICE A VERSA 'uses a Picaxe 28X1 'Picaxe's timer puts the time, in 10 minute increments, in TIME=b9 ' 2 74HC495 octal latches ' 1 phototransistor ''notes: w0=b1:b0, w1=b3:b2, w2=b5:b4, w3=b7:b6, w4=b9:b8,w5=b11:b10 'w6=b13:b12, w7=b15:b14, w8=b17:b16, w9=b19:b18, w10=b21,b20, w11=b23,b22 'w12=b25:b24, w13=b27:b26 'This program assumes power will first be applied to the LTF Picaxe project 'when it is light out. Here we will assume, when power is 'first applied, that the length of night=length 'of day or 12 hours and thus NL=73 symbol forcstLED=6 'green LED symbol minLED=5 'yellow LED symbol maxLED=4 'orange LED symbol warningLED=3'red LED symbol ser=2 'setup out2(23) to 595 ser pin 14--ser in symbol sckclk=1 'setup out1(22) to 595 sck pin 11--clock symbol rcklatch=0 'setup out0(21) to 595 rck pin 12--latch symbol mode=pin7 symbol up=pin6 symbol down=pin5 symbol lowpower=pin0 symbol whichsensor=b4 symbol airtemp=0 symbol phototransistor=3 symbol N=b5 symbol RawData=w11 symbol AvgData=b1 symbol night=bit0 'if night=1 it is night, otherwise night=0 symbol nightlastloop=bit1 symbol isit50minutes=bit2 symbol displaynumber=bit3 symbol first=bit4 symbol new=bit5 symbol outnible=b3 symbol outbyte=b2 symbol sum=s_w2 'originally w12 symbol bitcounter=b1 symbol number=b10 symbol AA=b27 symbol CUMTMPSR=s_w4 symbol TMPSR_AVG=b17 symbol NL=b16 'NightLength--length of night in 10 min increments symbol TMPSS=b6 'temperature at sunset symbol TMPSR=b7 'calculated Temperture at SunRise symbol TIMEL=b24 'time used for latest calculation symbol TMPL=b8 'temperatrue calculated at latest calculation symbol TIME=b9 symbol MINIMUM=b11 symbol MAXIMUM=b12 symbol WarningTemp=b13 symbol CALC_TMPSR=s_w0 symbol ACT_TMPSR=s_w1 'Note: w7, w10, s_w3, b18,b19 and b26 are used in calculations 'the software starts with these defaults burnt into the picaxe's eeprom EEPROM 0,(33) 'Warning Temp EEPROM 1,(73) 'NL (length of night (NightLengh) note:its 73 NOT 72 'this is to differentiate from happenstance correction EEPROM 2,(40) 'CALC_TMPSR calculated low EEPROM 3,(40) 'ACT_TMPSR actual low measured at sunrise EEPROM 4,(51) 'store TMPSS here #picaxe 28x1 start: 'the following 3 lines sets up interrupt for 10 minute ticks setintflags %10000000,%10000000 'set interrupt flags for timer settimer t1s_4 'sets it for 1 sec timer = 65535-599 'timer will overflow and set tof every 600 sec (10min) TIME=0 isit50minutes=0 high forcstLED 'the following commands pause 1000 'flash the four LEDs low forcstLED 'for a second each high minLED 'after LEDs flash pause 1000 'the LED display shows low minLED 'the present temperature in high maxLED 'degrees F pause 1000 low maxLED high warningLED pause 1000 low warningLED 'the following lines pulse forcstLED to 'indicate version number high forcstLED 'turn on forcstLED pause 1000 'for 1 second low forcstLED 'shut off for pause 500 '1/2 second gosub two 'turn on for 1/4 sec, off for 1/4 sec gosub two 'on for 1/4 sec, off for 1/2 sec low forcstLED goto skiproutines two: high forcstLED pause 250 low forcstLED pause 250 high forcstLED pause 250 low forcstLED pause 250 return skiproutines:let displaynumber=1 nightlastloop=0 'assume it was light when starting MINIMUM=44 MAXIMUM=83 read 0,WarningTemp read 1,NL 'measure and display temperature gosub DisplayTemp pause 5000 'for 2 seconds before doing anything else gosub presenttemp 'TMPSR=AvgData TMPSR_AVG=95 'find initially if its light or dark 'if light nightlastloop=0,if dark nightlastloop=1 gosub lightsensorhysteresis let first=1 new=0 AA=0 CUMTMPSR=0 disablebod '******************************************************** 'START OF MAIN ROUTINE Main: if lowpower=0 then let displaynumber=0 else let displaynumber=1 endif if up=0 then let displaynumber=1 endif 'the following indented code is to display NL 'this feature is undocumented since it may change if down=0 then let displaynumber=1 number=NL gosub displnum else gosub DisplayTemp endif gosub MINT 'returns the min measured temp since last reset gosub MAXT 'returns the max measured temp since last reset gosub lightsensorhysteresis 'if light level questionable wait gosub SUNSETANDSUNRISE'returns NL (night length)and TMPSS (tmp at sunset) gosub CALCLOWTEMP 'returns TMPSR_AVG (calculated temp at sunrise--low temp) gosub presenttemp if nightlastloop=0 then let TMPSR_AVG=99 endif if TMPSR_AVG<=WarningTEMP or AvgData<= WarningTEMP then high warningLED else low warningLED endif gosub threehoursyet gosub IsModeSwPRESSED goto main 'END OF MAIN ROUTINE '******************************************************************* '**subroutine** 'start clock going at sunset AND find the NightLength(NL) ie sunrise 'assume its dark if input 3 is low ie. Sum>925, light otherwise SUNSETANDSUNRISE: 'subroutine that obtains NL 'the following if/then statement is run when first starting up gosub lightsensorhysteresis '*****'the following routines occur at the instant of sunset if Sum>925 and nightlastloop=0 then 'if dark and it was light 'SUNSET! SUNSET! SUNSET! PUESTA DE SOL! TIME=0 'reset TIME to keep track of the length of night let first=1 new=0 AA=0 cumtmpsr=0 gosub presenttemp 'will return AvgData (temp at sunset) TMPSS=AvgData if TMPSS>18 then let TMPSR=TMPSS-15 else TMPSR=TMPSS-1 endif write 4, TMPSS pause 50 nightlastloop=1 'before leaving store 1 at nightlastloop 'the following 10 lines do the systems adaptation if ACT_TMPSRCALC_TMPSR then NL=NL-3 min 30 max 99' subtract 3 from NL write 1, NL pause 50 endif 'if ACT_TMPSR=CALC_TMPSR skip above modifications return endif 'to indicate it was dark 'if it wasn't the sunset then do the following '***the following routines check for sunrise and then 'stores in EEPROM the last calculated TMPSR gosub lightsensorhysteresis whichsensor=phototransistor gosub TakeData 'light data--when dark near 5V,light near 0V if Sum<925 and nightlastloop=1 then 'if light and it was dark 'at sunrise (turning from dark to light) set nightlength equal to time and store in eeprom at 1 'also make nightlastloop=0 so we know it is light especially when it 'turns dark(sunset) 'SUNRISE! SUNRISE! SUNRISE!--EL AMANECER! let NL=TIME 'store the length of night at nightlength 'if unusual happenstance occured (e.g. bird on sensor, eclipse, etc.) 'on light sensor then go back to default NL, which is 72 if NL<30 or NL>99 then 'if an unusual happenstance occured then let NL=72 'go back to 12 hour night, 12 hour day endif write 1, NL pause 50 let nightlastloop=0 gosub presenttemp TMPSR_AVG=AvgData let ACT_TMPSR=AvgData write 3, ACT_TMPSR pause 50 endif 'this isn't true starting up since nightlastloop=1 RETURN '**subroutine**displays the data in "number" in decimal displnum: if displaynumber=0 then let number=$FF goto displayblank endif if displaynumber=1 and number <> $FF then goto shownumber endif displayblank: if number = $FF then 'display 2 blanks if number =$FF outnible = 10 gosub outdigit outnible = 10 gosub outdigit pulsout rcklatch, 1 return endif if number = $FE then 'display blank C" if number = $FE outnible = 11 gosub outdigit outnible = 10 gosub outdigit pulsout rcklatch, 1 return endif shownumber: outnible=number % 10 'outnible now has lsd gosub outdigit 'send lsd outnible=number / 10 'outnible now has msd gosub outdigit pause 200 pulsout rcklatch, 1 return 'next is outdigit routine outdigit: ' 0 1 2 3 4 5 6 7 8 9 blank C lookup outnible, ($C0, $F9, $A4, $B0, $99, $92, $83, $F8, $80, $90, $FF, $46), outbyte for bitcounter = 0 to 7 if outbyte>=128 then outhi low ser goto clkout outhi: high ser clkout: pulsout sckclk, 1 outbyte=outbyte*2 next bitcounter return '******the following SUBROUTINE takes the MIN and MAX temperatures******** MINT: gosub presenttemp If AvgData<=MINIMUM then MINIMUM=AvgData endif return MAXT: gosub presenttemp If AvgData>=MAXIMUM then MAXIMUM=AvgData endif return 'if mode sw pressed once display min tmp and LED/down will reset it 'if mode sw pressed twice display max tmp and LED/down will reset it 'if mode sw pressed three times display forecast min and LED 'if mode sw pressed four times flash display warning temp and LED and 'then use up/down buttons to set warning temp 'if mode sw pressed fifth time return back to normal with display 'showing current temperature IsModeSwPressed: 'Was mode switch pressed once?If so display forecast 'min and light forecast LED if mode=1 then return endif pause 100 if mode=0 then displaynumber=1 pause 1000 do high forcstLED number=TMPSR_AVG min 1 max 99 gosub displnum pause 500 endif loop until mode=0 'Was mode switch pressed twice? If so display min timp and LED 'pressing "down sw" will reset min tmp low forcstLED if mode=0 then pause 500 do high minLED number=MINIMUM gosub displnum endif if down=0 then pause 500 gosub presenttemp MINIMUM=AvgData number=MINIMUM gosub displnum endif loop until mode=0 'Was mode switch pressed again (three times)?If so display max tmp and LED 'pressing down sw will reset max tmp low minLED if mode=0 then pause 500 do high maxLED number=MAXIMUM gosub displnum endif if down=0 then pause 500 gosub presenttemp MAXIMUM=AvgData number=MAXIMUM gosub displnum endif loop until mode=0 'Was mode switch pressed again? (four times)? If so display alarm 'LED and flash temp setting. If up or down pressed while display 'flashing set alarm temp with up and down switches. low maxLED if mode=0 then pause 500 do number=WarningTemp 'prepare to display WarningTemp gosub displnum 'display WarningTemp high warningLED pause 250 number=$FF 'prepare to turn off display gosub displnum 'display off low warningLED 'warningLED off pause 250 gosub is_up_pressed gosub is_down_pressed endif loop until mode=0 return 'if up switch pressed increase by 1 the WarningTemp is_up_pressed: read 0, WarningTemp if up=0 then inc WarningTemp write 0, WarningTemp pause 50 endif return 'if down switch was pressed decrease by 1 the WarningTemp is_down_pressed: read 0, WarningTemp if down=0 then dec WarningTemp write 0, WarningTemp pause 50 endif return '*********** the following SUBROUTINE measures and displays air temp******* DisplayTemp:gosub presenttemp number=AvgData 'number(b6) now has Temp in whole degF gosub displnum 'display temp on LED display... return '***the following routine takes present temperature presenttemp: let whichsensor=airtemp gosub TakeData AvgData=AvgData/2 min 1 max 99 return '************************************* '**subroutine**Take 10 bit temperature data and store it in AvgData... 'whichsensor stores the info on which sensor is beign used 'the variable RawData stores the info--in .5F resolution 'thus if RawData=150 then the actual temp is 75F TakeData: sum=0 For N=1 to 64 readadc10 whichsensor, RawData sum=sum + RawData pause 10 Next N AvgData=Sum/64 min 1 max 199 Sum=Sum/64 min 2 max 1023 return '*************************************** threehoursyet: if TIME>18 and first=1 then let CALC_TMPSR=TMPSR_AVG write 2, CALC_TMPSR pause 50 first=0 endif return '********************************************* '**CALCLOWTEMP uses NL, TMPSS, the present temp and present time 'to calculate the low temp at sunrise. It returns TMPSR 'it only calculates when time>=50 minutes and it returns the average 'of the previous calculated TMPSR and the latest TMPSR CALCLOWTEMP: if nightlastloop=0 then 'still light so no forecast of TMPSR LET TMPSR_AVG=99 'PUT OUT STATUS/ERROR CODE 99 TO INDICATE STILL LIGHT return endif let TIMEL=TIME if TIMEL<3 then TMPSR_AVG=98 'error 98 indicates too early for reliable forecast return endif gosub presenttemp let TMPL=AvgData if TMPL>=TMPSS then 'if temperature steady or rising then skip calculations let TMPSR_AVG=97 'and give error code of 97 return 'low forcstLED endif let w10=TMPSS-TMPL min 0 max 25 'watch out for outlier--too fast drop 'THE FOLLOWING STATEMENTS CHECK IF TEMP FALLING TOO FAST 'IF IT IS STATUS/ERROR CODE 96 WILL BE DISPLAYED if w10>10 and TIMEL<12 then TMPSR_AVG=96 return endif if w10>6 and TIMEL<6 then TMPSR_AVG=96 return endif if w10>4 and TIMEL<4 then TMPSR_AVG=96 return endif 'if sunset has occured more than 30 minutes earlier AND temperature 'is falling BUT NOT TOO FAST, AND while TMPSR calculations are being 'made, 60 of them havent been done yet THEN the display will show '94 when the FORECAST LED lights for 2 seconds 'on average, this period is 10 minutes, but at times can be longer if new=0 AND nightlastloop=1then let TMPSR_AVG=94 endif gosub EQN 'calculate TMPSR AA=AA+1 cumtmpsr=cumtmpsr+TMPSR if AA=60 then TMPSR_AVG=CUMTMPSR/AA new=1 CUMTMPSR=0 AA=0 if TMPSR_AVG>TMPL then let TMPSR_AVG=TMPL endif 'return endif low forcstLED return EQN: let number=TMPSR_AVG if TMPSR_AVG>TMPL AND TMPSR_AVG<93 then let number=TMPL endif gosub displnum high forcstLED pause 2500 gosub presenttemp 'these four lines make sure that the forcstLED let number=AvgData 'is on when the display is showing the forecasted temp gosub displnum low forcstLED read 1, NL pause 50 read 4, TMPSS pause 50 let w7=TMPSS-TMPL max 35 min 0'TMPSS=temp@sunset, TMPL=temp at TIMEL (in 10 min increments) let w7=2000*w7 max 50000 min 200 'note originally s_w3 was w13 let s_w3=TIMEL*TIMEL max 10000 min 1'TIMEL is latest time in 10 min increments let s_w3=2*NL*TIMEL-s_w3 min 1 let b26=w7/s_w3 min 1 max 99 'now round off b26 to the closest integer W10 = w7//s_w3*2 if w10 >= s_w3 then b26 = b26+1 endif b25=b26*NL*NL/2000 'NL is night length (same as sunrise since sunset time=0) 'now round off b25 to the closest digit w10=b26*NL*NL//2000 if w10>=1000 then b25=b25+1 endif '**done rounding off b25 let b19=2*NL*NL/2000 'now round off b19 to the closest digit let w10=2*NL*NL//2000 if w10>=1000 then b19=b19+1 endif 'done rounding off b19 let b19=b19*b26 let b18=TMPSS-b19+b25 min 1 max 98'shortly after sunset use calc TMPSR directly if b18>89 then let b18=1 return endif TMPSR=b18 gosub presenttemp if TMPSR>AvgData then let TMPSR=AvgData endif return '*****the following subroutine checks to make sure about sunset/sunrise lightsensorhysteresis: whichsensor=phototransistor stillunsure: whichsensor=phototransistor gosub TakeData if Sum <950 AND Sum >900 then goto stillunsure endif return '***timer interrupt routine follows*** interrupt: timer = 65535-599 INC TIME flag7=0 setintflags %10000000,%10000000 return