I am having difficulty using a Push Button to start a sequence of flashing LEDs. I know I have wired it correctly, as when I remove the Button, the LEDs flash in the sequence I programmed them to. I believe the problem may be with the Button itself, however, I am not sure. If it may help in solving the problem, I have included my sketch.
const int ledOne = 13;
const int ledTwo = 12;
const int ledThree = 8;
const int buttonPin = 4;
const int delayPeriod = 1000;
int buttonState = 0;
void setup()
{
pinMode (ledOne, OUTPUT);
pinMode (ledTwo, OUTPUT);
pinMode (ledThree, OUTPUT);
pinMode (buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH)
{
digitalWrite (ledOne, HIGH);
delay (delayPeriod);
digitalWrite (ledTwo, HIGH);
delay (delayPeriod);
digitalWrite (ledThree, HIGH);
delay (delayPeriod);
digitalWrite (ledOne, LOW);
digitalWrite (ledTwo, LOW);
digitalWrite (ledThree, LOW);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.