Arduino Programming – State change

How to program a state change functionality. ‘State change detection’ is a method to see when a button is pressed or released. You can use it to fire a different action each press of a button. For example the “Play/Pause” button on a cd-player behaves like that. The first press is play, the next press is pause, the next play again etc. Depending the state the action is different ( play > pause, pause > play ). In this tutorial I explain also the basic code structure ( setup, loop ) of Arduino script. Level : beginner with Arduino. ( Basic knowledge of programming principles like if/else and variables ). Download the Arduino ( .pde ) files : arduino_tutorial_statechange.zip OnOff.pde : State_change.pde : If you like to work with more than two states, do something like below. And use a switch or if statement later to perform some action on a certain stateNum value.