 #include "Nunchuck.h"
 #include <Wire.h> 
 #include <MozziGuts.h>
+#include <LowPassFilter.h>
+#include <ADSR.h>
 
-#define CONTROL_RATE 64 // powers of 2 please
-
-#define LEFT 0
-#define RIGHT 1
-#define UP 2
+#define CONTROL_RATE 128 // powers of 2 please
 
 int bumpy_input = 0;
 int constrain_input = 0;


#include <Oscil.h> // oscillator template
#include <tables/sin2048_int8.h> // sine table for oscillator
#include <tables/triangle2048_int8.h> // triangle table for oscillator
#include <tables/triangle_analogue512_int8.h> // saw table for oscillator

// use: Oscil <table_size, update_rate> oscilName (wavetable), look in .h file of table #included above
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);
Oscil <TRIANGLE2048_NUM_CELLS, AUDIO_RATE> aTri(TRIANGLE2048_DATA);
Oscil <TRIANGLE_ANALOGUE512_NUM_CELLS, AUDIO_RATE> aSaw(TRIANGLE_ANALOGUE512_DATA);

// Average the input signals
#include <RollingAverage.h>

int xStick;
int yStick;

LowPassFilter lpf;

ADSR <CONTROL_RATE, CONTROL_RATE> envelope;
ADSR <CONTROL_RATE, CONTROL_RATE> envelope2;

unsigned char volumeLeft;
unsigned char volumeRight;
unsigned char volumePitch;

int pressed = 0;
int unpressed = 0;
int play = 0;

unsigned int duration, attack, decay, sustain, release_ms;

byte gain = 0;
byte gain2 = 0;

void setup(){
  uint8_t error;
  
  error = Nunchuck.begin ();
  
  //Serial.begin(9600);
  
  /*if ( error )
  {
