2 leds off one command?

I want to use "ledpin" to represent both the 2 and 3 digital pins. How do I do that in the beginning setup?

int ledpin = (2,3); or int ledpin = [2,3];

I know these aren't right because I tried them, but how would I do this? Thanks a lot for the newb help!!!!

Depends on what you mean in this case.

Do you want both pin 2 and 3 to go high at the same time, or is your LED across pins 2 and 3 (Useful for Bicolors)

AFAIK, there is no easy way to make one command simultaneously change 2 pins. You can access the port directly, but I sense this is beyond scope.

digitalWrite(2,HIGH); digitalWrite(3,HIGH);

That'll execute fairly quickly so unless you need uS timing, I'd go this route.

http://arduino.cc/en/Reference/Array

:slight_smile:

It’s also possible to wire two LED’s to one output pin. Wire them in series and size the current limiting resistor for proper 20ma and the one output pin will light or turn off both LEDs.

Lefty

"Depends on what you mean in this case.

Do you want both pin 2 and 3 to go high at the same time, or is your LED across pins 2 and 3 (Useful for Bicolors)

AFAIK, there is no easy way to make one command simultaneously change 2 pins. You can access the port directly, but I sense this is beyond scope.

digitalWrite(2,HIGH); digitalWrite(3,HIGH);

That'll execute fairly quickly so unless you need uS timing, I'd go this route."

This would be fine, but I'm trying to fade 2 leds at the same time and at the same rate. So I don't want them just HIGH. However I am trying to do what you are describing.

I couldn't get the array thing to work. Would my code help?

Post some code.

What you try to do sounds like a perfect task for arrays.

This is probably a poor excuse for code but here is what I have… Thanks for the help!

int pinArrary[] = {9,10};
int ledpinHERD = 4;
int pulsewidth;

void setup()  {
}

void loop()  {
  for(pulsewidth=0; pulsewidth<=255; pulsewidth+=10){
    analogWrite(pinArray, pulsewidth);
    delay(50);
  }

 digitalWrite(pinArray, HIGH);
 delay(2000);
 digitalWrite(ledpinHERD, HIGH);
 delay(2000);
 digitalWrite(ledpinHERD, LOW);
 digitalWrite(pinArray, LOW);
  }

What do you want your code to do? In the end.

I want pins 9 and 10 to fade up to full brightness and then stay on while pin 4 goes HIGH. the 9,10, and 4 stay full brightness for 2 seconds and then all LOW.

Maybe something like this:

#include <Utility.h> //http://www.arduino.cc/playground/Code/Utility

const byte NUMBER_OF_PINS = 2; //change this to suit your needs
byte ledPin[NUMBER_OF_PINS] = {9,10};
int ledpinHERD = 4;
int pulsewidth = 0;

void setup(){
foreach(ledPin, NUMBER_OF_PINS, pinMode, OUTPUT);
pinMode(ledpinHERD,OUTPUT);
}

void loop() {
for (pulsewidth=0; pulsewidth<255; pulsewidth+=10){
foreach(ledPin, NUMBER_OF_PINS, analogWrite, pulsewidth);
delay(50);
}

foreach(ledPin, NUMBER_OF_PINS, digitalWrite, HIGH);
delay(2000);
digitalWrite(ledpinHERD, HIGH);
delay(2000);
digitalWrite(ledpinHERD, LOW);
foreach(ledPin, NUMBER_OF_PINS, digitalWrite, LOW);
}

You will need the Utility library, but it’s a small price to pay for the foreach I think. :sunglasses:

If you want to extend this to simultaneously fade pins 3,5,6,9,10 and 11 you just have to change these two lines:

const byte NUMBER_OF_PINS = 2; //change this to suit your needs
byte ledPin[NUMBER_OF_PINS] = {9,10};

To this:

const byte NUMBER_OF_PINS = 6; //change this to suit your needs
byte ledPin[NUMBER_OF_PINS] = {3,5,6,9,10,11};

wow that is great! after looking at the for a few minutes I’m starting to understand what’s going on! Thanks so much for the help!

I think you could also use:

PORTD = B00001100; // Sets pins 2 and 3 HIGH