Hi all
I’m trying something which feels like I should start a bit smaller. But I’m shooting anyway.
I accidentally ordered an adafruit mma8451 accelerometer. Which has a serial output and not 3 analog outputs… So I couldn’t really replicate Sam’s lightsaber theremin.
So I hooked it up to an arduino and tried to get the info out of the sensor and send it as a midi cc message to the computer… But I’m not there yet. This is currently my obvious code that isn’t working.
#include <Adafruit_MMA8451.h>
#include <Adafruit_Sensor.h>
Adafruit_MMA8451 mma = Adafruit_MMA8451();
const int axis = 3;
int axislevel [axis] = {0, 0, 0};
int axisinput [axis] = {mma.x, mma.y, mma.z};
int midiChannel = 1;
int midiCCnumbers [axis] = {16, 17, 18};
int midiCCvalues [axis] = {0, 0, 0};
void setup(void) {
Serial.begin(38400);
if (! mma.begin()) {
Serial.println("Couldnt start");
while (1);
}
Serial.println("MMA8451 found!");
mma.setRange(MMA8451_RANGE_2_G);
Serial.print("Range = "); Serial.print(2 << mma.getRange());
Serial.println("G");
}
void loop() {
for (int i = 0; i < axis; i++)
{
midiCCvalues[i] = floor(mma.read((axisinput[i]+8192)/129));
sendCC(midiChannel, midiCCnumbers[i], midiCCvalues[i]);
delay(10);
}
}
void sendCC(uint8_t channel, uint8_t control, uint8_t value) {
Serial.write(0xB0 | (channel & 0xf));
Serial.write(control & 0x7f);
Serial.write(value & 0x7f);
}
This part is getting in my way… (I think)
for (int i = 0; i < axis; i++)
{
midiCCvalues[i] = floor(mma.read((axisinput[i]+8192)/129));
sendCC(midiChannel, midiCCnumbers[i], midiCCvalues[i]);
delay(10);
}
The mma.read is 14 bit that needs to be converted to 8 bit cc… So -8192 to 8192 needs to become 0-127…
So it’s the value that’s read +8192 /129
However I have no idea how to code that! Someone suggested +MaxAnalogValue/mididivider… Which I don’t get. And it doesn’t work.
It’s always giving me trouble with this phrase:
midiCCvalues[i] = floor(mma.read((axisinput[i]+8192)/129));
So I need three values x,y and z. That needs to be converted to 8 bit…
Without the midi, I can read all the values just fine… in 14-bit.
Ow yeah… In my cv to midi… It was this line:
cvLevels[i] = floor(analogRead(analogInputs[i])/8);
Which is 10 bit to 8 bit.
Maybe I’ll give up on this. But not yet. I want my musical lightsaber!