Go Down

Topic: LEDS, cross fading, mapping question (Read 606 times) previous topic - next topic

danieljay

actually now I'm trying to crossfade between the 3 LED's and I'm having a road block conceptually on how to tackle this. i ended up making two more map functions, but i know this isn't necessary. so transition is led1 cross fades into led2; led 2 crossfades into led3 

danieljay

sorry, here is what I'm doing:

Code: [Select]
  outputValue1 = map(values, 25, 40, 0, 255);
  outputValue2 = map(values, 40, 25, 0, 255);
  outputValue3 = map(values, 2, 24, 0, 255);
  outputValue4= map(values, 24, 2, 0, 255);
  // change the analog out value:


  //analogWrite(led1, outputValue1);
  //  analogWrite(ledsignal, outputValue2);

  if(values >= 25 ){

    analogWrite(led1, outputValue1);
    analogWrite(ledsignal, outputValue2);
  }

  if(values >= 2 && values <= 24)
  {
    analogWrite(led2, outputValue4);
    analogWrite(ledsignal, outputValue3);


  }
}

PaulS

Code: [Select]
  outputValue1 = map(values, 25, 40, 0, 255);
  outputValue2 = map(values, 40, 25, 0, 255);
  outputValue3 = map(values, 2, 24, 0, 255);
  outputValue4= map(values, 24, 2, 0, 255);

There's a problem here. You are saying to map the value in values (please, is that name meaningful in any way?) from two different ranges to a value in the range 0 to 255. Suppose values contains 47. What do you expect the outputValueN values to be? What if it is 30? What if it is 20? What if it is 0?

The map function will, correctly, return a value that is not in the to range, if the input is not in the from range, so for any given value of values, you are going to get at least two output values that are greater than 255 or less than 0. Possibly 4 of them.

Go Up