int timer = 100; //delay time for blinking
int ledPin;
int sw = 11;
int a; // variable to set the ouput pin
void setup()
{
Serial.begin(9600);
//loop to initialize the pin mode of digital pins 2 to 7
pinMode(sw, INPUT);
while (ledPin < 8)
{
pinMode (ledPin, OUTPUT);
++ledPin;
} // end loop
} // end of setup()
void loop()
{
while(Serial.available())
{}
a=Serial.parseInt();
Serial.print(a);
//for loop to blink from pin 2 through to pin 7 with a delay time mentioned in timer
if (digitalRead(sw) == 1)
{
ledPin = 7;
while (ledPin >= 2)
{
digitalWrite (ledPin, HIGH);
delay (timer);
digitalWrite (ledPin, LOW);
Serial.println(ledPin);
--ledPin;
}// end of for loop
//for loop to blink from pin 7 through to pin 2 with a delay time mentioned in timer
ledPin = 2;
while (ledPin < 7)
{
digitalWrite (ledPin, HIGH);
delay (timer);
digitalWrite (ledPin, LOW);
++ledPin;
} // end for loop
}
else if(digitalRead(sw) == 0)
{
ledPin = 7;
while (ledPin >= 2)
{
digitalWrite (ledPin, LOW);
--ledPin;
}
}
} // end program