Refinement of arduino code