Explain me this phenomenon

This is the setup PIN2---82Ohm---LED---380Ohm---GND PIN3---------------/

And the loop digitalWrite(ledPin, HIGH); digitalWrite(bedPin, LOW); delay(1000);

digitalWrite(ledPin, LOW); digitalWrite(bedPin, HIGH); delay(1000);

I thought it would stay ON with slight change in brightness every second, but instead it is ON 1 sec and OFF 1 sec If I unplug pin1 or pin2 it still blinks the same pattern

Why???

The code toggles (reverses) the state of the two pins every second. If the led is connected across the pins, it will be on for the second that the pin connected to the anode is HIGH and off when that pin is taken low.

Yes, but both pins are connected to positive LED leg, and at any time either Pin2 or Pin3 are High, so it should light constantly.... right? (When I take out 82Ohm resistor does light constantly)

Can you say exactly what is connected to ledPin and bedPin, or even better, post a picture

Aren't you short-circuiting pins 2 and 3 when you do this?

Perhaps you want to set the other pin to INPUT (high-impedance) rather than LOW?

If you switched one pin high and left the other floating, instead of switching it low, it would probably work. Most of the current will run from the high pin to the low pin through the 82 ohm resistor in alternating directions.

ledPin = Pin2 (with 82Ohm resistor) bedPin = Pin3

OK I guess I am shortcicuiting it...

If I would put diodes would it be safe then PIN2--diode--82Ohm---LED---380Ohm---GND PIN3--diode-------------/

I am just trying to modify the brightness without using PWM so this is the test

Now those are some random resistor values ( I think? ) lol
But what you’re doing when you’re setting a LOW, is making another ground more or less.

Try something like this: (untested) LED through a 330 ohm resistor (or any value higher than that up to 2.2k ish)
Mind you, this might not be what you’re looking for… this will dim an LED from fully off to fully on and back down to 0 in a few seconds.

int ledPin = 11;


void setup(){
pinMode(ledPin, OUTPUT);
}

void loop(){
int i;
for (i=0; i<=255; i++){  // starting at 0, increment of 1 up to 255
analogWrite(ledPin, i);
}
for (i=255; i>0; i--){   // starting at 255, decrease by 1, until at 0
analogWrite(ledPin, i);
}
}

(right after I posted this, I read you didn’t want to use PWM… haha)
I’m no help here then, my only guess to do it digitally would be to use a digital potentiometer, but I’m sure there’s another way.

Its not clear if pin3 is connected to ground or just to a diode and nothing else. Can you say a little more about what each pin is connected to

I think I understand this: PIN2--diode--82Ohm---LED---380Ohm---GND

what is this? PIN3--diode-------------/

Sorry to post again… should’ve asked in my earlier post but didn’t even think about it.

Can anyone explain to me why you would use two separate resistors, before and after the LED? (Other than just not having the right value)
Isn’t that basically setting up a “Voltage Divider” ?
Using just the 380 ohm to Ground would work fine.

And actually last night, I got some Samples from MARL (woot), 6 Dual Color LEDs on a PCB 2x3 mount. Hooked up the top 3 and kind of used the HIGH and LOW idea, worked out well, but I can only assume there’s a better way to code it…

How it’s set up, the positive of each of the colors is setup respectively.
So if pinRed[2], HIGH, then pinGreen[3], LOW will turn on the first LED in Red. pinGreen[3], HIGH and pinRed[2], LOW will turn the LED red.

What it’s doing is reading a potentiometer in 4 ranges. Each range will do a variety of blinking. (as you can tell from the code)
This is my first time actually hand writing a code without needing much information, so I’m proud! (Insight welcome, and appreciated!)

int pinRed[] = {2,4,6};
int pinGreen[] = {3,5,7};
int potPin = 0;
int count = 0;
const int sensorMin = 0;
const int sensorMax = 1024;

void setup(){
for (count=0;count<5;count++) {
  pinMode(pinRed[count], OUTPUT);
  pinMode(pinGreen[count], OUTPUT);
}
}

void loop(){
int val = analogRead(0);
int range = map(val, sensorMin, sensorMax, 0, 3);

switch (range) {
case 0:
  fullRed();
  delay(750);
  allOff();
  delay(750);
  break;
case 1:
  fullRed();
  delay(750);
  fullGreen();
  delay(750);
  break;
case 2:
  fullGreen();
  delay(750);
  allOff();
  delay(750);
  break;
case 3:
  blinkage;
  break;
}
}

  
void fullRed(){
  int i;
  for (i=0;i<3;i=i+1){
  digitalWrite(pinGreen[i], HIGH);
  digitalWrite(pinRed[i], LOW);
  }
}

void fullGreen(){
  int i;
  for (i=0;i<3;i=i+1){
  digitalWrite(pinRed[i], HIGH);
  digitalWrite(pinGreen[i], LOW);
  }
}
  
void allOff(){
  int i;
  for (i=0; i<3; i = i++){
  digitalWrite(pinRed[i], LOW);
  digitalWrite(pinGreen[i], LOW);  
  }
}

void blinkage(){
int i;
  for (i=0; i<3; i = i++){
    digitalWrite(pinRed[random(i)], HIGH);
    digitalWrite(pinGreen[random(i)], LOW);
  }
}

2 mem: Pin3 is connected to LED + ------/ should have been graphic representation of bended wire to LED

CaptainObvious you are right I can take only one resistor between pin and LED... I will try with that

From what I can tell your circuit should work, it's probably your code that is wrong.

What you are effectively trying to achieve is two different circuits for driving the LED:

a) PIN2---82Ohm---LED---380Ohm---GND

and

b) PIN3--------------LED---380Ohm---GND

The position of the resistors in the LED driver circuit is irrelevant. The resistor is there to limit the current flowing in through the LED, it does not matter if it is between the pin and the LED or between the LED and GND or as you have it, on either side of the LED. All that matters is the total resistance.

To achieve each of the circuits drawn above you need two different states:

a) set PIN2 as an output and drive high out, set PIN3 as an input

b) set PIN2 as an input, set PIN3 as an output and drive high out

In state a) the 82 Ohm resistor is in circuit and you get less current through the LED. PIN3 is an input and so does not drive out and so adds no current to the LED drive.

In state b) the 82 Ohm resistor is effectively shorted out inside the microcontroller to 5V by PIN3 driving high and so you get more current through the LED.

You might get away with keeping PIN2 set as an output driving high, but when in state b) PIN2 will still source some current through the 82 Ohm resistor which will make the LED a bit brighter, but give it a shot, it might work.