Nathan Koch

CC Lab: Homework Week One

Wednesday, August 30th 2017

The Code

const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin

bool prevButtonState; bool ledIsBlinking;

void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT);

// initialize serial communication at 9600 bits per second: Serial.begin(9600); }

void loop() { bool buttonState = digitalRead(buttonPin); if (prevButtonState && !buttonState) { ledIsBlinking = !ledIsBlinking; } prevButtonState = buttonState; if (ledIsBlinking) { digitalWrite(ledPin, HIGH); delay(500); digitalWrite(ledPin, LOW); delay(500); } else { digitalWrite(ledPin, LOW); } }