Skip to main content Skip to navigation

Using Buttons to Control Flashing

You will learn how to write a program that changes depending on if you press a button.

Find the Worksheet here: (PDF Document) Using Buttons to Control Flashing

The Worksheet requires you to start with a basic template program. Click and drag to select the program below, then copy and paste it into the Arduino Software.

* Button template program 
* Written by Stephen Pithouse on behalf of Warwick Volunteers 

int button = 9; //button connected to pin 9
int LED = 13; //use the built in LED
int buttonState = 0; //used later

void setup() {
pinMode(button, INPUT); //button is an input
pinMode(LED, OUTPUT); //LED is an output

void loop(){
buttonState = digitalRead(button);
if(buttonState == 0){
digitalWrite(LED, HIGH);
digitalWrite(LED, LOW);