Moved pin direction declarations, moved lights() call to after bounds checks (from main function)