Ok, so I'm still farily new and inexperienced at writing code. I've got the begginings of a wavetable oscillator sketch going, just with a fixed pitch, contant note on, and 1 potentiometer controlling a wavetable. I've been building it up small steps at a time, and so far everything works. It has to read the pot to decide what blend of wavetable it will use and then do some maths before pumping out numbers to the 8bit DAC, and this runs really slow.

So... I decided to have a crack at interupts for the first time. Thought I'd got the hang of it, but it isnt working.

Here's the slow but working code (I've removed the wavetable figures to save clutter)

```
void setup()
{
DDRC = 255; // 8 bit DAC on port C
Serial.begin(9600); // begin serial communication
}
unsigned int osc1; // final oscillator 1 mix
short mix4; // used to work out which oscillators to mix between
unsigned int two; // floats here avoid calc error when calculating osc1
unsigned int three;
unsigned int four;
unsigned int five;
unsigned int six;
unsigned int sine;
unsigned int out;
short i = 0; // "i" is soon to become the array index, and is set to start at index 0
unsigned char xtwo[256] = // xtwo[] is an array that holds the sample data for a x2-base251 wave
{
};
unsigned char xthree[256] = // xthree[] is an array that holds the sample data for a x3-base251 wave
{
};
unsigned char xfour[256] = // xfour[] is an array that holds the sample data for a x4-base251 wave
{
};
unsigned char xfive[256] = // xfive[] is an array that holds the sample data for a x5-base251 wave
{
};
unsigned char xsix[256] = // xsix[] is an array that holds the sample data for a x6-base251 wave
{
};
unsigned char xsine[256] = //sine wave array
{
};
void loop()
{
int mix = analogRead(A0); // potentiometer that controls the blend between xthree and xfive
mix4 = map(mix, 0, 1024, 0, 4); // works out which wavetables will be used (have to map an extra sector to take imaginary number 1024
two = xtwo[i];
three = xthree[i]; // convert array numbers into float to help xoutput calc
four = xfour[i];
five = xfive[i];
six = xsix[i];
sine = xsine[i];
if(mix4 == 0)
osc1 = ((two*(255-mix))/255) + ((three*mix)/255); // calculate the different oscillator mixes
if(mix4 == 1)
osc1 = ((three*(511-mix))/255) + ((four*(mix-256))/255);
if(mix4 == 2)
osc1 = ((four*(767-mix))/255) + ((five*(mix-512))/255);
if(mix4 == 3)
osc1 = ((five*(1023-mix))/255) + ((six*(mix-768))/255);
out = (osc1+(sine))/2;
PORTC = out; // output the mixed signal
i++; // increase i in increments to cycle through the waveforms
if(i >= 256) // check if the index is at the end of the sample
i = 0; // if it is, reset the sample to 0
}
```

Here is my attempt at using an interupt to read the potentiometer and decide on the wavetable mix:

```
unsigned char xtwo[256] = // xtwo[] is an array that holds the sample data for a x2-base251 wave
{
};
unsigned char xthree[256] = // xthree[] is an array that holds the sample data for a x3-base251 wave
{
};
unsigned char xfour[256] = // xfour[] is an array that holds the sample data for a x4-base251 wave
{
};
unsigned char xfive[256] = // xfive[] is an array that holds the sample data for a x5-base251 wave
{
};
unsigned char xsix[256] = // xsix[] is an array that holds the sample data for a x6-base251 wave
{
};
unsigned char xsine[256] = //sine wave array
{
};
long previousTime = 0; // will store last time LED was updated
int wave = 0;
short waveSelect = 0; // used to work out which oscillators to mix between
short i = 0; // "i" is soon to become the array index, and is set to start at index 0
unsigned int two; // floats here avoid calc error when calculating osc1
unsigned int three;
unsigned int four;
unsigned int five;
unsigned int six;
unsigned int sine;
volatile unsigned int osc1 = xtwo[i]; // final oscillator 1 mix, starts with just xtwo (changed via interupt)
unsigned int out; // total output
boolean change = false; // just to test interupt
void setup()
{
DDRC = 255; // 8 bit DAC on port C
Serial.begin(9600); // begin serial communication
attachInterrupt(A0, waveMixer, CHANGE); // interupt: go to the ISR/void called "wave" when pot attached to A0 changes
}
void loop()
{
two = xtwo[i]; // convert array numbers into int to help xoutput calc
three = xthree[i];
four = xfour[i];
five = xfive[i];
six = xsix[i];
sine = xsine[i];
out = (osc1+(sine))/2;
PORTC = out; // output the mixed signal before doing anything else for speed and accuracy?
i++; // increase i in increments to cycle through the waveforms
if(i >= 256) // check if the index is at the end of the sample
i = 0; // if it is, reset the sample to 0
Serial.println(change);
}
void waveMixer()
{
wave = analogRead(A0); // potentiometer that controls the blend between xthree and xfive
waveSelect = map(wave, 0, 1024, 0, 4); // works out which wavetables will be used (have to map an extra sector to take imaginary number 1024
if(waveSelect == 0)
osc1 = ((two*(255-wave))/255) + ((three*wave)/255); // calculate the different oscillator mixes
if(waveSelect == 1)
osc1 = ((three*(511-wave))/255) + ((four*(wave-256))/255);
if(waveSelect == 2)
osc1 = ((four*(767-wave))/255) + ((five*(wave-512))/255);
if(waveSelect == 3)
osc1 = ((five*(1023-wave))/255) + ((six*(wave-768))/255);
change = true;
}
```

I have used a boolean called "change" to try and work out if the interupt is working, and it doesn't respond.

Cheers for your advice and help in advance

Pete