Sunday, October 18, 2009

Shanna B Assignment #2

int led1Pin = 9; // declare pin 9
int led2Pin = 10; // declare pin 10
int switchPin = 2; // the switch is connected to pin 2
int buttonState; // declare a variable to hold the button state

void setup()
{
pinMode(switchPin, INPUT); // Set the switch pin as INPUT
pinMode(led1Pin, OUTPUT); // LED pin 9 as OUTPUT
pinMode(led2Pin, OUTPUT); // LED pin 10 as OUTPUT


}

void loop() {
buttonState = digitalRead(switchPin); // read the initial state
if(buttonState == HIGH) { // LED (wave) if statement
for (int i=0; i<=20; i++) // set loops for 20 times { digitalWrite(led2Pin, LOW); digitalWrite(led1Pin, HIGH); delay(100); digitalWrite(led1Pin, LOW); digitalWrite(led2Pin, HIGH); delay(100); digitalWrite(led2Pin, LOW); } delay(2000); // pauses for 2 seconds } } video

No comments:

Post a Comment