Any way to Use all Ints that meet a criteria to make a decision?

analogWrite(ALL currently HIGH pins, i);

is what I’m looking to do…
I know the lazy way to do it, would a counter work? and just check all the pins?

for  (int thisPin = 0; thisPin < 10; thisPin++) {

if (thispin==HIGH) {
for (i=0; i<255; i++) {        //Fade in
    analogWrite(thispin, i);
delay(10);

}
if I did this I would have to put the delay AFTER the thisPin for loop correct?
This is using PWM… would that cause each pin to not start counting until the previous PWM had finished?

(I’m trying this at the same time, but I just know there’s gonna be problems : )

This is using PWM… would that cause each pin to not start counting until the previous PWM had finished?

No, PWM starts going as soon as you set it.

if I did this I would have to put the delay AFTER the thisPin for loop correct?

No.

for  (int thisPin = 0; thisPin < 10; thisPin++) {

All the pins 0 to 10 are not capable of PWM.
Using pins 0 & 1 is not a good idea as those are used for serial communications.

for  (int thisPin = 0; thisPin < 10; thisPin++)
{
  if (thispin==HIGH)
  {

The if statement will be true for thisPin == 1, only.

Perhaps you want to actually read the state of the pin, and compare that state to HIGH?

blah : )

pins 9-11 then, whatever :stuck_out_tongue:

I think I am/am I trying to make an array out of the pins that are High?

Like say:
for (int thisPin = 9; thisPin < 11; thisPin++)
if (thispin ==HIGH) Add to an array somehow?
analogWrite(That array, i);

I think I am/am I trying to make an array out of the pins that are High?

Like say:
for (int thisPin = 9; thisPin < 11; thisPin++)
if (thispin ==HIGH) Add to an array somehow?
analogWrite(That array, i);

No. Where are you reading the state of the pin?

for(int p=0; p<11; p++)
{
if(digitalRead(p) == HIGH)
analogWrite(somePin, i);
}

oh, duh. My version is setting them high by accident, thanks! :)

(Wait... can I read Output pins with DigitalRead?) (Or was that where bitRead(PORTD, pin) is used?)

hoping arrays are as easy as I think.... is that what I should be using? or is there a simpler way?

Wait… can I read Output pins with DigitalRead?

No, but you can read them with digitalRead. All you will get is the last value you set the pin to.

Or was that where bitRead(PORTD, pin) is used?

For this, you get to go spend an hour with the reference section.

Hah, fair 'nuff, works fine up to that point, no need for bitReading ports

Now can I Add to an Array from a function? in Wiring…
(http://www.arduino.cc/playground/Code/DynamicArrayHelper is Brutal, no luck there)

There must be an easier and less retarded way than just counting the pins manually :frowning:

Ala:

case '9':  if(digitalRead(2) == LOW) { for (i=0; i<255; i++) {  analogWrite(2, i); }}
    if(digitalRead(3) == LOW) { for (i=0; i<255; i++) {  analogWrite(3, i); }}
      if(digitalRead(4) == LOW) { for (i=0; i<255; i++) {  analogWrite(4, i); }}
          delay(10);        //should be a random delay since this is a fade in/out
          
          if(digitalRead(2) == LOW) { for (i = 255; i>0; i--) {  analogWrite(2, i); }}
    if(digitalRead(3) == LOW) { for (i = 255; i>0; i--) {  analogWrite(3, i); }}
      if(digitalRead(4) == LOW) { for (i = 255; i>0; i--) {  analogWrite(4, i); }}
          delay(10);        //same random

Also, right now this just causes a flicker w. no ‘i’ change, I know I messed up the order/brackets but where? / : (

If you ran your code down the page, put each curly brace on a separate line, and properly indented the code, it would be perfectly easy to see what the “problem” is.

case '9':
  if(digitalRead(2) == LOW)
  {
    for (i=0; i<255; i++)
    {
      analogWrite(2, i);
    }
  }
  if(digitalRead(3) == LOW)
  {
    for (i=0; i<255; i++)
    {
      analogWrite(3, i);
    }
  }
  if(digitalRead(4) == LOW)
  {
    for (i=0; i<255; i++)
    {
      analogWrite(4, i);
    }
  }

Think about how long it takes to execute each for loop. How fast can you see changes in the LED intensity?

Actually that made no difference :frowning: still have no idea where the problem is.

I can see changes in the LED intensity at 30-40ms? I have no idea where to use this. (Other than keeping delay below 30)

Got it working though, I just randomly nested things until it worked : /

 case '9':  
  for (i=0; i<255; i++) {  if(digitalRead(GREEN) == LOW) {analogWrite(GREEN, i);}    /*delay(10)*/if(digitalRead(BLUE) == LOW) {   analogWrite(BLUE, i);}    /*delay(10)*/if(digitalRead(RED) == LOW) {  analogWrite(RED, i);}    delay(5);}  
   for (i=255; i>0; i--) {  if(digitalRead(GREEN) == LOW) {analogWrite(GREEN, i);}    /*delay(10)*/if(digitalRead(BLUE) == LOW) {   analogWrite(BLUE, i);}    /*delay(10)*/if(digitalRead(RED) == LOW) {  analogWrite(RED, i);}    delay(5);}
                  //should be a random delay since this is a fade in/out

Whatever I tried :slight_smile: it still has 1ms of a random Pin at the lowest point, but you only notice it on White
(Code to control an RGB LED BTWLMNOP)

Actually that made no difference smiley-sad still have no idea where the problem is.

This loop:

for (i=0; i<255; i++)
{
analogWrite(2, i);
}

requires something like 20 to 30 machine instructions per iteration of loop. Each instructions takes 62.5 nanoseconds to execute.

The whole loop completes in less than a millisecond, during which time the LED intensity goes from off to full on. Did you see that fade, or did the LED appear to bang on?

A delay BETWEEN loops does not affect the fact that the LED ramps from off to full on faster than you can see (or ramps from full on to off).