Using digitalWrite() to set 2 pins high at the same time.......

And you have got individual current limiting resistors for each colour?

What's with all the stuff of setting the pins as inputs and enabling the pullups?

yes if the condition is true (the sensor input is 1.10 to 1.20) the output is LOW otherwise its HIGH

setting the pins to output allows me to make the digital pins set to HIGH as default and turn them LOW to light the leds.
The RGB led works with a common 5+volts and ground to each of the three pins for each color

setting the pins to output allows me to make the digital pins set to HIGH as default and turn them LOW to light the leds.

Yes, I know that, but why do you set them all to be inputs first.

You still haven't answered this:

And you have got individual current limiting resistors for each colour?

i.e. is there a resistor between each cathode and the output pin it is attached to?

negative no resistor....

Those two if tests do exactly the same thing or did I miss something?

Essentially that code is

Code:

if (PPO >= 1.10 && PPO <= 1.20) {
digitalWrite(blue1, LOW); //light blue and green
digitalWrite(green1, LOW);
} else {
digitalWrite(blue1, HIGH);
digitalWrite(green1, HIGH);
}

these to test are turning the blue and green led on & off at the same time to get the secondary color

At this time there is nothing wrong with the code I've written it works perfect, the only thing I want to add to it is to be able to set 2 colors(blue and green ) from LOW back to HIGH without interfering with the single color(blue) of the same pin.

So, you have nothing to limit the current into the pin, and you're wondering why it isn't working?

There must be something else at play here because as has been mentioned the time between these

digitalWrite(blue1, LOW); //light blue and green
digitalWrite(green1, LOW);

is only a few uS and that's not long enough to see anything.

If the LEDs are on the same port you can use direct port manipulation to achieve what you want.

negative no resistor....

That's not good.

I think we need to see all of the code and a schematic as well.


Rob

It sounds like your common 5V is comming from an output pin and not the 5V supply. That would explain why one colour affects the other.
Without a resistor in each cathode you are damaging your arduino and eventually you will fry it and distroyed it.

Thank you for this. This information saved me from asking a super NOOB question releated to the 3D printer firmware I am writing for the Mega 2560. I am assuming that the same variables apply for the 2560's ports?

I know this is an old thread, though I would rather dig up an old thread that has still valid information than needlessly post a new thread.

Just to be clear would something along the lines of:

CurStepA = ++CurStepA & 7;
PORTB = (PORTB & 0x0F0) | StepVal[CurStepA];

Work to advance a stepper attached to the pins corresponding to AVR PORTB pins 0 through 3 by one half step? Assuming of course that CurStepA holds the current index into StepVal[] and StepVal[] is globally declared as:

unsigned char StepVal[8] = {0x09, 0x08, 0x0C, 0x04, 0x06, 0x02, 0x03, 0x01};

Also which ports/pins are exported on the mega2560? I can find the Arduino pin names/numbers though not the AVR equivalents (which would be needed to do this).

What if you want to turn one pin on HIGH and one LOW at the same time? For Example:

void setup(){
pinMode (LEDPin1, OUTPUT);
pinMode (LEDPin2, OUTPUT);
}

void loop(){

digitalWrite(LEDPin1, HIGH);

digitalWrite(LEDPin2,LOW);

delay(50);

digitalWrite(LEDPin, LOW);

digitalWrite(LEDPin, High);

delay(50);
}

When I use this output code, the LEDPin2 gets stuck in the HIGH and never turns off. I would like the system to loop and have LEDPin1 "on" while LEDPin2 is "off" at the same time. Then I would like LEDPIn1 to be "off" and LEDPin2 to be "on" at the same time. However, with this combination I get LEDPin1 blinking but LEDPin2 staying stuck in the permanent "on" status. Anybody have any ideas?
Thanks you for you suggestions.

digitalWrite(LEDPin, LOW); ????

digitalWrite(LEDPin, High); ????

If you want to effect a change on multiple pins at the same time, declare a union

union
{
   struct
   {
       byte    bit_0: 1;
       byte    bit_1: 1;
       byte    bit_2: 1;
       byte    bit_3: 1;
       byte    bit_4: 1;
       byte    bit_5: 1;
       byte    bit_6: 1;
       byte    bit_7: 1;
   };
   byte port_bits;
} port_data;

You can then assign whatever values you want to,

port_data.bit_n

without changing anything. When you're done with all your changes you then load those into the appropriate register,

PORTx = port_data.port_bits;

This method is extensible to updating all three ports at the same time, but that discussion is for another time.

Instead of:

PORTB = (PORTB & 0x0F0) | StepVal[CurStepA];

Try:

PORTB = (PORTB & 0xF0) | (StepVal[CurStepA]);

Looks like that came from this code for a 28BYJ-48, step pattern may be different on your motor:

/* pin 8 to pin 1 on ULN2003, pin 16 to pink,   coilA
       9 to pin 2,                15    yellow, coilC
      10 to pin 3,                14    orange, coilB
      11 to pin 4,                13    blue,   coilD
  Type a value for microseconds per step in top of Serial
  Monitor and click [Send] or press [ENTER].
   
*/
uint32_t tStart,
         tEnd = 878964UL; // microseconds per step
const byte fSteps [8] = {0x01, 0x02, 0x04, 0x08, 0x01, 0x02, 0x04, 0x08};
const byte hSteps [8] = {0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09};
byte cntr = 0;
bool dir = false; // set true for opposite direction (CW/CCW)

void setup()
{
  Serial.begin(9600);
  DDRB = 0x0F; // set pins 8,9,10,11 to OUTPUT
}

void loop()
{
  if(Serial.available() > 0)
  {
    tEnd =  Serial.parseInt();
    Serial.println(tEnd);
  }
  if (micros() - tStart > tEnd)
  {
    tStart += tEnd;
    PORTB = (PINB & 0xF0) | (hSteps[cntr & 0x07]);
    dir ? cntr-- : cntr++;
  }
}

outsider:
Instead of:

PORTB = (PORTB & 0x0F0) | StepVal[CurStepA];

Try:

PORTB = (PORTB & 0xF0) | (StepVal[CurStepA]);

Both variants are absolutely equvalent, why should someone try that?

Are you into Voodoo or something?

1 "0" difference but probably don't matter, 0x0F0 vs 0xF0

outsider:
1 "0" difference but probably don't matter, 0x0F0 vs 0xF0

Between the 0x and the hex number you can insert any number of zeros without changing the value,
like between the 0b and the binary value.

It's often done to align a bunch of constants visually, or to make the number of hex digits even for readability.

Your suggestion even makes the number of digits odd, which is... odd.

So maybe I should stop suggesting things... What you think?