Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
Posted: Mon Jan 07, 2013 11:07 pm Post subject:
Esplora -> 2xCV + Trigger Subject description: Or at least that's the goal....
I got an Esplora over the weekend, and while distracting myself from a misbehaving Baby-8 Sequencer, decided to use a 2 channel 12 bit SPI DAC I had lying around (MPC4922) to use the Esplora as a CV generator.
I want each axis of the joystick to be one CV, and the rightmost button on the diamond as trigger. I intend to scale the two axes by setting the slider and clicking the top and bottom buttons on the diamond (haven't decided which is X and which is Y yet). And for future fun I'll make the fourth button change modes, indicating mode with the RGB LED at the lower right.
Even though I think this should work with just the one chip, I am still somewhat space constrained, so I glued three cheap jacks together and glued them to the board.
Then I got silly and figured that one of the targets for this is my cigarlab+ which has CV in for pitch on two oscillators, but most other control voltages are bananas, so i glued/soldered two bananas to the two CV outputs. Obviously there are grounding issues so using them will require me to plug in the 1/4" jack for the trigger, even if I don't use that trigger mode.
All this is built and planned, but not one bit of coding yet . Hopefully in the next week....
2013-01-07_21-59-40_708.jpg
Description:
Top View before jacks
Filesize:
322.82 KB
Viewed:
517 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.
2013-01-07_23-53-41_365.jpg
Description:
Looking down the barrel
Filesize:
422.55 KB
Viewed:
459 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.
2013-01-07_23-53-56_379.jpg
Description:
flying over
Filesize:
435.03 KB
Viewed:
454 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.
2013-01-07_23-54-10_235.jpg
Description:
and behind
Filesize:
451.93 KB
Viewed:
425 Time(s)
This image has been reduced to fit the page. Click on it to enlarge.
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
Posted: Tue Jan 08, 2013 9:57 pm Post subject:
aaand success At least good enough to call done for now, I implemented all the ideas I wanted to, though they could probably be done more gracefully or perhaps in a more musically useful way.
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
Posted: Wed Jan 09, 2013 8:29 pm Post subject:
Theory of Operation:
The Joystick controls two control voltages, one for each axis.
The slider is used in conjunction with the up and down buttons on the button pad to set the Y and X axis voltage ranges, respectively. You set the slider to some approximation of how "wide" you want the range to be, and then hit the respective X or Y axis button.
The left button changes the mode.
The right button is the trigger/gate button.
In Mode 0, the LED is red, and the right button sends a trigger out the trigger jack (10ms I believe, 5V).
In Mode 1, the LED is green, and the right button is a gate, so the trigger jack sends out 5V until you release the button.
In Mode 2, the LED is blue, but there's nothing configured to do anything... yet I was thinking of firing some kind of arpeggiation, or perhaps if the slide has limited the range, let you set an offset voltage, so that the lower left isn't always 0V, 0V on the CV jacks. Or maybe simply center whatever the range is, we'll see.
Code:
/*
* set up to use MCP4922 on board taking over LCD slot to generate CVs
*
*
*/
#include <Esplora.h>
#include <SPI.h>
/*
This array holds the last sensed state of each of the buttons
you're reading.
Later in the code, you'll read the button states, and compare them
to the previous states that are stored in this array. If the two
states are different, it means that the button was either
pressed or released.
*/
boolean buttonStates[4]; // only care about the 4 diamond buttons
/*
This array holds the names of the buttons being read.
Later in the sketch, you'll use these names with
the method Esplora.readButton(x), where x
is one of these buttons.
*/
const byte buttons[] = {
SWITCH_RIGHT,
SWITCH_LEFT,
SWITCH_UP,
SWITCH_DOWN,
};
const byte X = 0;
const byte Y = 1;
int scaling[2];
int mode = 0; // values 0==trigger 1==gate, 2==uncommitted
int modes = 3;
int modeRed[] = {
180, 0, 0
};
int modeGreen[] = {
0, 140, 0
};
int modeBlue[] = {
0, 0, 180
};
SPI.begin();
SPI.setBitOrder(MSBFIRST);
// Default is DIV4, or 4MHz for an AVR at 16MHz system clock
SPI.setClockDivider(SPI_CLOCK_DIV2); // MCP4922 should be able to go up to 20MHz or even 32MHz
// but half the system clock is as fast as we can go
SPI.setDataMode(SPI_MODE0); //just to be sure.
void loop() {
// Iterate through all the buttons:
for (byte thisButton=0; thisButton<4; thisButton++) {
boolean lastState = buttonStates[thisButton];
boolean newState = Esplora.readButton(buttons[thisButton]);
// if button, do action
if (lastState != newState) {
if (!newState) { // Button press down; normally high
switch (thisButton) {
case 0: do_trigger(newState);
break;
case 1: change_mode();
break;
case 2: scale(Y);
break;
case 3: scale(X);
break;
}
} else if ((mode == 1) && (thisButton == 0) && newState) {
do_trigger(newState);
}
}
// Store the new button state, so you can sense a difference later:
buttonStates[thisButton] = newState;
}
// read X & Y from Joystick
// joystick goes from -512 to +512, center is 0
// the direction is opposite expectations, hence the - instead of +
int xAxis = ((512 - Esplora.readJoystickX()) / scaling[X]) - 1;
int yAxis = ((512 - Esplora.readJoystickY()) / scaling[Y]) - 1;
if (xAxis<0) {
xAxis = 0;
}
if (yAxis<0) {
yAxis = 0;
}
// write X & Y to DAC
doDAC(X, xAxis);
delay(10); // give some time to settle, may not be necessary
doDAC(Y, yAxis);
delay(10); // give some time to settle, may not be necessary
}
void scale(int axis) {
// note that slider high value is to the left, we want the reverse behavior
int slider = Esplora.readSlider();
if (slider > 1023) {
slider = 1023;
}
scaling[axis] = 1024 / (1024 - slider);
//Serial.print("Slider: ");
//Serial.println(Esplora.readSlider());
//Serial.print("Scale factor: ");
//Serial.println(scaling[axis]);
}
void doDAC(byte port, int value) {
// port 0 == A on DAC, port 1 == B on DAC
// value is 1-1024, needs to be scaled up *4 but limited to 4095
value *= 4;
//Serial.print("port: ");
//Serial.print(port);
//Serial.print(" value: ");
//Serial.println(value);
switch (port) {
case 0: value |= 0x3000; //select channel A, gain = 1
break;
case 1: value |= 0xB000; // select channel B, gain = 1
break;
}
digitalWrite(mySS, LOW); // manual slave select
SPI.transfer(highByte(value));
SPI.transfer(lowByte(value));
digitalWrite(mySS, HIGH);
}
Joined: Mar 20, 2012 Posts: 2177 Location: Chicago
Audio files: 16
Posted: Wed Jan 09, 2013 8:33 pm Post subject:
Not posting stripboard because 1) mine is a bastard thing and 2) I don't have a stripboard editor that I like and don't have patience to go find one right now. The important thing is that the two 10-pin pin headers that mate with the Esplora have 20 columns between them (not inclusive), so they'd be column 1 and column 22, and that nothing of either is used except for the 3rd and 4th pins of the right header.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum