hi all
i made a realy complicated (at least for me) led Sequencer. (on arduino DUE)
and for now everything i made seems to work perfect.
i store the sequence on a SD card.
and i can read the data as i like it to be.
the data i get are no of steps, fadetime, scenetime and outputchannel, currentvalue.
i store and compare the fadetime and scenetime with currentvalue, prevvalue on sram.
this way i can increase or decrease the output value with scenetime and fadetime useing micros.
then i try to change the output with some math.
like :
Master dimmer.
individual dimmer per Sequence (i run i can run more then one at the same time)
individual tap sync ( i can change it on the fly)
individual Fadetime ( i can change it on the fly)
individual constrain function ( i can change it on the fly, this make the saw wave smaller or bigger at both sides) example normal the Sequence = 0 to 255 after this fuction you get 10 to 245
all seems to work perfect.
but now i try to add a Sine wave to it.
this work ok with all the functions you see above but when i do the Sine with the Contrain everything goed wrong, i just cant seem to let it work.
and to get a idea how i do the math i show you some code i made.
this line constrains the value, makes a avr for Scenetime, fadetime, tapsync, currentvalue and prevalue
currentval[z] = avrmainpot[num] * currentval[z]; // contrain value with potvalue
_Arv[z] = (avrfadetime[num] * avrtap[num] * ((uint32_t)_Fade[num] * 1000.00)) / abs(currentval[z] - _Prevval[z]);
// Arv[channel] = float * float * long / abs(byte - byte)
now how do i play it back
if (currentval[z] > _Prevval[z] && currentval[z] > _value[z]) { // Do i need to Increase Value?
_value[z] = _Prevval[z] + (micros() - _PrevMillis[z]) / _Arv[z]; // Yeah!!! lets increase the value with fade time
}
else if (currentval[z] < _Prevval[z] && currentval[z] < _value[z]) { // Do i need to Decrease Value?
_value[z] = _Prevval[z] - (micros() - _PrevMillis[z]) / _Arv[z]; // Yeah!!! lets Decrease the Value with fade time
}
i get _prevmillis when i fetch new data from the sdcard.
now _value[z] is a nice looking sawtooth wave.
and when i do
output = sin((_value[channel] / 81.184) + 4.712) * 127.5 + 127.5;
i get a nice looking sinewave.
now i like to constrain the sinewave and i only get strange result, and cant get i head around it.
so maby someone knows a solution?