static void InitializeLEDFlow() { SetLEDs(0x0f); SetAccelerometerMainConfig( LIS302DL_LOWPOWERMODE_ACTIVE| LIS302DL_DATARATE_100| LIS302DL_XYZ_ENABLE| LIS302DL_FULLSCALE_2_3| LIS302DL_SELFTEST_NORMAL); //Wait one second for data to stabilize Delay(100); SetAccelerometerFilterConfig( LIS302DL_FILTEREDDATASELECTION_BYPASSED| LIS302DL_HIGHPASSFILTER_LEVEL_1| LIS302DL_HIGHPASSFILTERINTERRUPT_1_2); SetLEDs(0); if(!PingAccelerometer()) for(;;) SetLEDs(0x05); //Read zero calibration data ReadRawAccelerometerData(zero); }
static void AudioCallback(void *context, int buffer) { int8_t components[3]; int32_t dx; static uint32_t phase = 0; uint32_t phasediff; int16_t *samples = GET_AUDIO_BUFFER(buffer); ReadRawAccelerometerData(components); dx = (components[0]-zero[0]) + 0x3f; phasediff = dx * 0x9; for(int i = 0; i < 128; i++) { phase += phasediff; if (!(phase & 0x8000)) samples[2*i+0] = samples[2*i+1] = 32767; else samples[2*i+0] = samples[2*i+1] = -32768; } ProvideAudioBuffer(samples, 256); }
void ReadCalibratedAccelerometerData(int8_t values[3]) { int8_t newValues[3]; ReadRawAccelerometerData(newValues); values[0]=(int8_t)newValues[0]-calibrationVector[0]; values[1]=(int8_t)newValues[1]-calibrationVector[1]; values[2]=(int8_t)newValues[2]-calibrationVector[2]; }
static void RunLEDFlow() { int8_t components[3]; ReadRawAccelerometerData(components); int32_t dx=components[0]-zero[0]; int32_t dy=components[1]-zero[1]; int32_t r=sqrti(dx*dx+dy*dy); dx=(dx<<12)/r; dy=(dy<<12)/r; x+=r*25; // x+=components[0]-zero[0]; // y+=components[1]-zero[1]; int leds=0; leds|=(((x+dx)>>14)&1)<<1; leds|=(((x-dx)>>14)&1)<<3; leds|=(((x+dy)>>14)&1)<<0; leds|=(((x-dy)>>14)&1)<<2; SetLEDs(leds); }
void CalibrateAccelerometer(void) { ReadRawAccelerometerData(calibrationVector); }