Hi, first post here after a long time searching.
what i have setup is a ribbon controller pin 1 to gnd, pin 2 to analog in0, pin 3 to 5v.
Basically setup as a potentiometer.
I have the range of the ribbon controlling pitch (changing brightness of LED via PWM).
it also holds the pitch at the last value when the gate signal is off.
As pin 2 is completely disconnected from the ribbon when it is not pressed, im using the arduino to detect a voltage across it and produce a gate trigger (so notes only sound when the ribbon is pressed).
This i have working fine, but i now want to implement a way to fade the gate in when pressed, hold at fully on, and then fade out after it is released.
Also at anytime during the gate fading in and out i want the pitch to be changeable, as well as being retriggerable. For example, i have the attack set to 1 second, after 500ms i release the ribbon and then press it again, the gate should begin fading in from zero not continue on through the entire fade in, fade out, sequence.
This is the code without any fading of the gatePin. Im assuming i need a way of fading without using delay() as it has to run the entire cycle before i can input a new pitch or even stop it halfway through.
int sensorP = A0;
int pitchPin = 11;
int gatePin = 10;
int pitch = 0;
int pitchOut = 0;
int gate = 0;
void setup()
{
pinMode(pitchPin, OUTPUT);
pinMode(gatePin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
gatefun();
pitchfun();
Serial.print("pitch = " );
Serial.print(pitch,DEC);
Serial.print("\t gate = ");
Serial.println(gate, DEC);
}
void gatefun()
{
gate = analogRead(sensorP);
if(gate < 20)
{
analogWrite(gatePin, 0);
}
else
{
analogWrite(gatePin, 255);
}
}
void pitchfun()
{
if(gate < 20)
{
}
else
{
pitch = analogRead(sensorP);
pitchOut = map(pitch, 25, 1000, 0, 170);
analogWrite(pitchPin, pitchOut);
}
}
Thanks.
Jaxn.