Improve deviceState in Arduino code