Dear Diyers,
I'm trying to make a ADSR (envelop generator for synthesizer ) with arduino
i use a 7HC595 with a 2R ladder to make a DAC to generate envelop
A input Multiplexer 4051 scan 8 potentiometers. Only Four potentiometers Attack, Decay, Sustain, Release are used.
I would like to replace this part of code because i couldn 't use Delay function in my program
How can i modify my code to use a Timer ?
thank you for your help
void loop()
{
//scanner les entrées du 4051
for (count=0; count<=7; count++)
{
InitialiseShift();
ValuePotScan();
}
oldgate = stategate;
stategate = digitalRead (gate);
if (stategate == HIGH && oldgate != stategate){
for (int i =0; i<255 ; i++){
digitalWrite (latchPin, 0);
shiftOut (dataPin,clockPin,i );
digitalWrite (latchPin, 1);
delayMicroseconds ( valuepot[0] +1);
}
for (int j=255; j> valuepot[2]; j--){
digitalWrite (latchPin, 0);
shiftOut (dataPin,clockPin,j );
digitalWrite (latchPin, 1);
delayMicroseconds ( valuepot[1] +1);
}
}
if (stategate ==LOW && oldgate == HIGH){
for (int k = valuepot[2] ; k>0; k--){
digitalWrite (latchPin, 0);
shiftOut (dataPin,clockPin,k );
digitalWrite (latchPin, 1);
delayMicroseconds ( valuepot[3] +1);
}
}
}