void Accelerometer::refresh() { if (!pinsAreValid()) { Serial.println("WARNING: Accelerometer pins are not configured to valid digital pins"); return; } int newX = readAxis(xPin); int newY = readAxis(yPin); int newZ = readAxis(zPin); deltaX = newX - x; deltaY = newY - y; deltaZ = newZ - z; x = newX; y = newY; z = newZ; }
double MMA_7455::readAxisInG(char axis) { char val; //Variables for the values from the sensor val = readAxis(axis); //Read out the 'axis' Axis int8_t x = (int8_t)val; double xG = convertToG(x); return xG; }
void MMA_7455::autoCalibrateOffset(int N) { double x_axis_offset = 0, y_axis_offset = 0, z_axis_offset = 0; for(int i = 0 ; i < N ; i++ ) { x_axis_offset += (int8_t)readAxis('x'); y_axis_offset += (int8_t)readAxis('y'); z_axis_offset += (int8_t)readAxis('z'); delay(10); } x_axis_offset /= N; y_axis_offset /= N; z_axis_offset /= N; _x_axis_offset = -1 * x_axis_offset; _y_axis_offset = -1 * y_axis_offset; _z_axis_offset = (2*63/_sensitivity) - z_axis_offset; }
int16_t LIS3MDL_TWI::readZ() { return readAxis(OUT_Z); }
int16_t LIS3MDL_TWI::readY() { return readAxis(OUT_Y); }
int16_t LIS3MDL_TWI::readX() { return readAxis(OUT_X); }
void loop() { // read and scale the two axes: int invertY = digitalRead(switchPin); int xReading = readAxis(xAxis, 0)*2; int yReading = readAxis(yAxis, !invertY); int leftx = readAxis(xAxisleft, 0); int lefty = readAxis(yAxisleft, 1); // Keyboard left stick if (leftx > 0) { Keyboard.press(leftright); Keyboard.release(leftleft); Serial.print("right\n"); } if (leftx < 0) { Keyboard.release(leftright); Keyboard.press(leftleft); } if (leftx == 0) { Keyboard.release(leftright); Keyboard.release(leftleft); } if (lefty > 0) { Keyboard.press(leftdown); Keyboard.release(leftup); } if (lefty < 0) { Keyboard.release(leftdown); Keyboard.press(leftup); } if (lefty == 0) { Keyboard.release(leftdown); Keyboard.release(leftup); } // Move the mouse Mouse.move(xReading, yReading, 0); // read the mouse button and click if (digitalRead(leftButton) == LOW) { // A single click if (!Mouse.isPressed(MOUSE_LEFT)) { Mouse.press(MOUSE_LEFT); } } else { if (Mouse.isPressed(MOUSE_LEFT)) { Mouse.release(MOUSE_LEFT); } } if (digitalRead(rightButton) == LOW) { Keyboard.press(' '); } else { Keyboard.release(' '); } // Shift is right stick if (digitalRead(12) == LOW || digitalRead(13) == LOW) { Keyboard.press(KEY_LEFT_SHIFT); } else { Keyboard.release(KEY_LEFT_SHIFT); } delay(responseDelay); }
int16_t LIS331DLH_TWI::readY() { return readAxis(OUT_Y); }
int16_t LIS331DLH_TWI::readZ() { return readAxis(OUT_Z); }
int16_t LIS331DLH_TWI::readZ() { hal.console->printf_P("Z "); return readAxis(OUT_Z); }
int16_t LIS331DLH_TWI::readX() { return readAxis(OUT_X); }
int16_t LIS331DLH_TWI::readY() { hal.console->printf_P("Y "); return readAxis(OUT_Y); }
int16_t LIS331DLH_TWI::readX() { hal.console->printf_P("X "); return readAxis(OUT_X); }
int16_t L3G4200D_TWI::readZ() { return readAxis(OUT_Z); }
int16_t L3G4200D_TWI::readY() { return readAxis(OUT_Y); }
int16_t L3G4200D_TWI::readX() { return readAxis(OUT_X); }