int led1Pin = 11; // declare pin 11
int led2Pin = 10; // declare pin 10
int led3Pin = 9; // declare pin 9
int led4Pin = 8; // declare pin 8
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); // declare the LED pin 11 as OUTPUT
pinMode(led2Pin, OUTPUT); // declare the LED pin 10 as OUTPUT
pinMode(led3Pin, OUTPUT); // declare the LED pin 9 as OUTPUT
pinMode(led4Pin, OUTPUT); // declare the LED pin 8 as OUTPUT
}
void loop() {
buttonState = digitalRead(switchPin); // read the initial state
if(buttonState == HIGH) { // LED "wave" if statement
for (int i=0; i<=15; i++) // set loops for 15 times
{
digitalWrite(led4Pin, LOW);
digitalWrite(led1Pin, HIGH);
delay(100);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, HIGH);
delay(100);
digitalWrite(led2Pin, LOW);
digitalWrite(led3Pin, HIGH);
delay(100);
digitalWrite(led3Pin, LOW);
digitalWrite(led4Pin, HIGH);
delay(100);
digitalWrite(led4Pin, LOW);
}
delay(2000); // pauses for 2 seconds
}
}
Tuesday, October 6, 2009
Putra | Script 02
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment