Go Down

Topic: LED Won't Turn Off - Me TOO! (Read 123 times) previous topic - next topic

SteveMatta

Hi folks:

I've searched this one and there are several posts, but the solutions don't speak to my issue.  Ii have four LEDs on a project board with a resistor on each positive lead.  I have the cathode pins on the ground strip - common ground jumper to GND on the Arduino Uno.

So, with that in mind, I fire up the following code - it starts working great, but when I turn off the LEDs, the first one (LED1) does NOT turn off.  I've tried several things - different pinouts, etc., but it won't turn off.  PLEASE!!! Have a look and help me if you see an issue:


//#define LED0 GND

#define LED1 A0
#define LED2 A1
#define LED3 A2
#define LED4 A3



void setup() {

pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);


}

void loop() {
  // put your main code here, to run repeatedly:
     
  digitalWrite(LED1,1);
  delay(1000);
  digitalWrite(LED2,1);
  delay(1000);
  digitalWrite(LED3,1);
  delay(1000);
  digitalWrite(LED4,1);
  delay(1000);
 
  digitalWrite(LED4,0);
  digitalWrite(LED3,0);
  digitalWrite(LED2,0);
  digitalWrite(LED1,0);
  }

Grumpy_Mike

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

We also need a schematic because your description is a bit vague.

However, try putting a  delay(1000 ) ; as the last instruction in the loop, because the first instruction in the loop follows the last almost immediately.

SchnoppDog

Quote
However, try putting a  delay(1000 ) ; as the last instruction in the loop, because the first instruction in the loop follows the last almost immediately.
Might be worth a try.
If it's not helping. maybe switching leds will help?

maxim2511

Grumpy Mike have right. Add delay at the end of code at switching of led's, because instantly first Led is switch on instantly.

Go Up