Home: symbol RELAY1 = 0 ' represents output 2 symbol RELAY2 = 1 ' represents output 1 symbol SETIME = 3000 ' symbol LIGHT = b0 'Set current light variable to memory location b0 symbol DAY = b1 'Set day light variable to memory location b1 symbol DARK = b2 'Set dark light variable to memory location b3 symbol CHECK = b3 'Set check boolean to memory location b3 symbol COUNTER = b4 'Set counter variable to memory location b4 'Populate the variables LIGHT = 0 DAY = 100 DARK = 30 CHECK = 1 COUNTER = 1 DELAY = 3000 Do pause 1000 readadc 4, LIGHT ' Store the analogue value in variable "LIGHT" If LIGHT >= DAY and input3 = 0 and CHECK = 1 then 'If it is day time and door is closed then open door Pause 3000 readadc 4, LIGHT If LIGHT >= DAY and input3 = 0 then High RELAY1 High RELAY2 Pause SETIME Low RELAY1 Low RELAY2 let CHECK = 0 End if ElseIf LIGHT < DARK and input3 = 1 and CHECK = 0 then ' If it is dark and door is open then close door Pause 3000 readadc 4, LIGHT If LIGHT <= DARK and input3 = 1 then For COUNTER = 1 to 96 ' Uses a counter when closing the door and continues to close the door until the end of the counter reaches the end. High RELAY1 PAUSE 250 If COUNTER < 96 and input3 = 0 then Gosub OBSTRUCTION End if Next Low RELAY1 let CHECK = 1 End if End if Loop OBSTRUCTION: High RELAY2 ' Activate second relay to reverse door Pause 1000 Low RELAY2 ' Turn off both relays Low RELAY1 If COUNTER < 5 then ' Reset counter to allow for the door being raised COUNTER = 1 else COUNTER = COUNTER - 5 End if Return