Add all sensor parameters
parent
53d957ea0f
commit
c57f219c5d
|
@ -11,10 +11,32 @@ BLEMIDI_CREATE_DEFAULT_INSTANCE()
|
|||
unsigned long t0 = millis();
|
||||
bool isConnected = false;
|
||||
|
||||
// accelerometer
|
||||
float x, y, z;
|
||||
float mx, my, mz; // midi mapped
|
||||
// midi
|
||||
// offsets CC:
|
||||
// 0-63: left hand
|
||||
// 64-127: right hand
|
||||
enum side {LEFT, RIGHT=64};
|
||||
int hand = LEFT;
|
||||
int midichannel = 1;
|
||||
|
||||
// accelerometer
|
||||
float accx, accy, accz;
|
||||
float maccx, maccy, maccz; // midi mapped
|
||||
float accmag; // magnitude
|
||||
|
||||
// gyroscope
|
||||
float gyrox, gyroy, gyroz;
|
||||
float mgyrox, mgyroy, mgyroz;
|
||||
// magnetometer
|
||||
float magx, magy, magz;
|
||||
float mmagx, mmagy, mmagz;
|
||||
|
||||
float maxx, maxy, maxz;
|
||||
|
||||
float fmap(float x, float in_min, float in_max, float out_min, float out_max)
|
||||
{
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// When BLE connected, LED will turn on (indication that connection was successful)
|
||||
|
@ -66,7 +88,20 @@ void setup()
|
|||
Serial.println();
|
||||
Serial.println("Acceleration in G's");
|
||||
Serial.println("X\tY\tZ");
|
||||
|
||||
|
||||
Serial.print("Gyroscope sample rate = ");
|
||||
Serial.print(IMU.gyroscopeSampleRate());
|
||||
Serial.println(" Hz");
|
||||
Serial.println();
|
||||
Serial.println("Gyroscope in degrees/second");
|
||||
Serial.println("X\tY\tZ");
|
||||
|
||||
Serial.print("Magnetic field sample rate = ");
|
||||
Serial.print(IMU.magneticFieldSampleRate());
|
||||
Serial.println(" uT");
|
||||
Serial.println();
|
||||
Serial.println("Magnetic Field in uT");
|
||||
Serial.println("X\tY\tZ");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -75,32 +110,68 @@ void setup()
|
|||
void loop()
|
||||
{
|
||||
if (IMU.accelerationAvailable()) {
|
||||
IMU.readAcceleration(x, y, z);
|
||||
IMU.readAcceleration(accx, accy, accz);
|
||||
IMU.readGyroscope(gyrox, gyroy, gyroz);
|
||||
IMU.readMagneticField(magx, magy, magz);
|
||||
|
||||
mx = x * 64 + 64;
|
||||
my = y * 64 + 64;
|
||||
mz = max(10, abs(z) * 1000);
|
||||
accmag = sqrt(accx*accx+accy*accy+accz*accz);
|
||||
// accmag = map(accmag, 0, 1000, 0,127);
|
||||
|
||||
maccx = fmap(accx,-4.0,4.0, 0.0,127.0);
|
||||
maccy = fmap(accy,-4.0,4.0, 0.0,127.0);
|
||||
maccz = fmap(accz,-4.0,4.0, 0.0,127.0);
|
||||
//mgyrox = gyrox/2000 * 64 + 64;
|
||||
//mgyroy = gyroy/2000 * 64 + 64;
|
||||
//mgyroz = gyroz/2000 * 64 + 64;
|
||||
mgyrox = map(gyrox, -2000,2000, 0.0, 127.0);
|
||||
mgyroy = map(gyroy, -2000,2000, 0.0, 127.0);
|
||||
mgyroz = map(gyroz, -2000,2000, 0.0, 127.0);
|
||||
// mz = max(10, abs(z) * 1000);
|
||||
mmagx = fmap(magx, 0,60, 0,127);
|
||||
mmagy = fmap(magy, 0,60, 0,127);
|
||||
mmagz = fmap(magz, 0,60, 0,127);
|
||||
|
||||
Serial.print(mx);
|
||||
Serial.print('\t');
|
||||
Serial.print(my);
|
||||
maxx = max(magx, maxx);
|
||||
maxy = max(magy, maxy);
|
||||
maxz = max(magz, maxz);
|
||||
|
||||
// Serial.print(mx);
|
||||
// Serial.print('\t');
|
||||
// Serial.print(my);
|
||||
// Serial.print(y);
|
||||
// Serial.print('\t');
|
||||
// Serial.println(z);
|
||||
Serial.println();
|
||||
// Serial.println();
|
||||
}
|
||||
|
||||
MIDI.read();
|
||||
|
||||
|
||||
|
||||
if (isConnected && (millis() - t0) > mz)
|
||||
if (isConnected && (millis() - t0) > 10)
|
||||
{
|
||||
t0 = millis();
|
||||
|
||||
MIDI.sendNoteOn (my, mx, 1); // note 60, velocity 100 on channel 1
|
||||
Serial.println("ping");
|
||||
delay(mz);
|
||||
MIDI.sendNoteOff(my, mx, 1);
|
||||
// MIDI.sendNoteOn (my, mx, 1); // note 60, velocity 100 on channel 1
|
||||
MIDI.sendControlChange(0 + hand, maccx, midichannel);
|
||||
MIDI.sendControlChange(1 + hand, maccy, midichannel);
|
||||
MIDI.sendControlChange(2 + hand, maccz, midichannel);
|
||||
MIDI.sendControlChange(3 + hand, mgyrox, midichannel);
|
||||
MIDI.sendControlChange(4 + hand, mgyroy, midichannel);
|
||||
MIDI.sendControlChange(5 + hand, mgyroz, midichannel);
|
||||
MIDI.sendControlChange(6, accmag * 100, midichannel);
|
||||
MIDI.sendControlChange(7 + hand, mmagx, midichannel);
|
||||
MIDI.sendControlChange(8 + hand, mmagy, midichannel);
|
||||
MIDI.sendControlChange(9 + hand, mmagz, midichannel);
|
||||
Serial.print(mmagx);
|
||||
Serial.print('\t');
|
||||
Serial.print(mmagy);
|
||||
Serial.print('\t');
|
||||
Serial.println(mmagz);
|
||||
// Serial.print('\t');
|
||||
// Serial.println(accmag * 100);
|
||||
// Serial.println("ping");
|
||||
// delay(mz);
|
||||
// MIDI.sendNoteOff(my, mx, 1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue