I am a math teacher trying to get acquainted with the Arduino Uno and trying to learn a few basic things to teach my students. I am trying to run the sketch below, which is working, however, the first LED light is bright, the second one a bit dimmer, and the third one dimmer still. The brightness cycle repeats each time the loop runs, bright, dimmer, dimmer. I have each one grounded with a 220 resistor to the common column on the breadboard that then connects to the ground on the Arduino. Can anyone explain to me in really simple terms why the lights are successively dimmer and how to fix the code or the set up.
/* Button-Turns on and off three LED's connected to digital pins 10, 9, and 8
when pressing a pushbutton attached to pin 7.
*/
const int buttonPin = 7; // constant value - the number of the pushbutton pin connected to 7
int ledPin = 10; // variable value - the number of the LED pin starts with 10
int buttonState = 0; // variable value - for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
if (ledPin >8){
digitalWrite(ledPin, HIGH); // If button is pushed, buttonState reads HIGH, turns starts sequence.
delay(80);
digitalWrite(ledPin, LOW);
delay(80);
ledPin--;
digitalWrite(ledPin, HIGH);
delay(80);
digitalWrite(ledPin, LOW);
delay(80);
ledPin--;
digitalWrite(ledPin, HIGH);
delay(80);
digitalWrite(ledPin, LOW);
delay(80);
ledPin--;
} else {
ledPin = 10;
}
} else {
digitalWrite(ledPin, LOW); // If button is not pushed, buttonState reads LOW, turns LED off.
}
}
(I don't know why that happy face appeared in the code, it is an eight)