SIK_circuit05_pushButton_v2 by SparkFun SIK Examples

State machine example. Each time you press the button, the Arduino changes "state" or "mode". This is shown in displaying a different color.
This example is a variation on the SIK circuit #5. Instead of two buttons and an LED, we use one button and an RGB LED. sketch illustrates using a simple pushButton and an RGB LED to sequence through several program states using what is called a state machine. Each time the button is pressed, a state variable is incremented. There is a nested if-else statement below that then does something different depending on the value of the state variable. <span style="display:block; text-align:center;"><iframe width="450" height="380" src="https://123d.circuits.io/circuits/883745-sik-circuit-5_v2-push-button-rgb/embed" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></span> This is a very useful trick for creating menus, incrementing through steps, or controlling your projects.

Embed This Sketch

Use the following HTML code to embed the sketch code above in your blog or website.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/sketch:128600" frameborder="0"></iframe>

Embed The Serial Monitor

You can also embed the Serial Monitor section! Just use this HTML code.

<iframe style="height: 510px; width: 100%; margin: 10px 0 10px;" allowTransparency="true" src="https://codebender.cc/embed/serialmonitor" frameborder="0"></iframe>