Updated for typos etc after verifying with Arduino program