Modified writePin to use togglePin