implementing Photocell logic