oh sorry here it is there are multiple bits of code for the whole thing which are broken up into separate files, i thought that the whole thing would have been in one file? ...
#include "dsp.h"
// create an array for the delay
byte array[2000];
//define variables
int j;
int fx;
int mode;
int value50;
int value300;
int value10000;
int delayed;
void setup() {
setupIO();
//set initial values
j = 50;
value50 = 50;
value300 = 300;
value10000 = 1000;
delayed = 0;
}
void loop() {
//check status of the effect potentiometer and rotary switch
readKnobs();
// *************
// ***bitcrush**
// *************
if(mode == 6){
value300 = 1 + ((float) fx / (float) 3);
if(delayed > value300) {
byte input = analogRead(left);
input = (input >> 6 << 6);
output(left, input);
delayed = 0;
}
delayed++;
}
// ***************
// ***Overdrive***
// ***************
if(mode == 7){
value50 = 1 + ((float) fx / (float) 20);
byte input = analogRead(left);
input = (input * value50);
output(left, input);
}
// *************************
// ***short crunchy delay***
// *************************
if(mode == 9){
for(int i = 0; i < 2000; i ++) { // set up a loop
//array[i] = array[i] + array[i - 1]; //removes noise and some delay
output(left, array[i]);
array[i] = analogRead(left);
}
}
// **********************
// ***clean helicopter***
// **********************
if(mode == 10){
value10000 = fx * 10;
if(delayed > value10000) {
for(int i = 0; i < 2000; i ++) { // set up a loop
array[i] = array[i] + array[i - 1]; //removes noise and delay
output(left, array[i]);
array[i] = analogRead(left);
}
delayed = 0;
}
delayed++;
}
// ********************
// ***ring modulator***
// ********************
if(mode == 11){
value50 = 1 + ((float) fx / (float) 20);
byte input = analogRead(left);
input = (input * j);
output(left, input);
j = j - 1;
if (j <= 0) {
j = value50;
}
}
// ************************
// ***YOUR AWESOME SOUND***
// ************************
if(mode == 12){
//************************************
//insert your awesome effect code here
//************************************
}
}
void readKnobs(){
//read the rotary switch
//and determine which effect is selected
//dividing by 75 ensures proper discrete values
//for if statements above
mode = analogRead(2);
mode = mode / 75;
//reads the effects pot to adjust
//the intensity of the effects above
fx = analogRead(3);
}
#include "dsp.h"
#include "timers.h"
#include "WProgram.h"
void setupIO() {
// prepare left
waveformGenerationMode(3, fastPWM);
timerPrescale(3, 1);
analogWrite(3, 0);
// prepare right
waveformGenerationMode(5, fastPWM);
timerPrescale(5, 1);
analogWrite(5, 0);
// faster input
analogReference(INTERNAL);
analogPrescale(analogPrescale32);
}
void output(int channel, short value) {
if(channel == left) {
pwm3 = value >> 2;
pwm11 = (value & B11) << 6;
} else if(channel == right) {
pwm5 = value >> 2;
pwm6 = (value & B11) << 6;
}
}
#define left 0
#define right 1
void setupIO();
void output(int channel, short value);
#include "timers.h"
#include "WConstants.h"
int getTimer(int pin) {
switch(pin) {
case 5: case 6: return 0;
case 9: case 10: return 1;
}
return 2; // 3, 11
}
int getChannel(int pin) {
switch(pin) {
case 6: case 10: case 11: return 0;
}
return 1; // 3, 9, 5
}
// - - -- timer settings
void waveformGenerationMode(int pin, int type) {
int timer = getTimer(pin);
int wgm = type == phaseCorrect ? B001 : B011;
if(timer == 0) {
TCCR0B &= ~(B1 << 3); // clear WGM02
TCCR0A &= ~B11; // clear WGM01 and WGM00
TCCR0A |= wgm; // set WGM01 and WGM00
} else if(timer == 2) {
TCCR2B &= ~(B1 << 3); // clear WGM23
TCCR2A &= ~B11; // clear WGM21 and WGM20
TCCR2A |= wgm; // set WGM21 and WGM20
}
}
void waveformGenerationMode(int pin, int type, int bits) {
int timer = getTimer(pin);
if(timer == 1) {
TCCR1B &= ~(B11 << 3); // clear WGM13 and WGM12
TCCR1A &= ~B11; // clear WGM11 and WGM10
TCCR1B |= (type << 3); // set WGM12
TCCR1A |= (bits - 7);
}
}
void timerPrescale(int pin, int prescale) {
int timer = getTimer(pin);
if(timer == 0) {
TCCR0B &= ~B111; // clear CS02 CS01 CS00
TCCR0B |= getPrescale01(prescale);
} else if(timer == 1) {
TCCR1B &= ~B111; // clear CS12 CS11 CS10
TCCR1B |= getPrescale01(prescale);
} else if(timer == 2) {
TCCR2B &= ~B111; // clear CS22 CS21 CS20
TCCR2B |= getPrescale2(prescale);
}
}
int getPrescale01(int prescale) {
switch(prescale) {
case 1: return B001;
case 8: return B010;
case 64: return B011;
case 256: return B100;
case 1024: return B101;
default: return B000;
}
}
int getPrescale2(int prescale) {
switch(prescale) {
case 1: return B001;
case 8: return B010;
case 32: return B011;
case 64: return B100;
case 128: return B101;
case 256: return B110;
case 1024: return B111;
default: return B000;
}
}
// - - -- analog prescaling
void analogPrescale(int divisionFactor) {
ADCSRA &= ~B111; // clear analog prescale
ADCSRA |= divisionFactor;
}