void MMA7455::begin() { #else void MMA7455::begin(uint8_t pin_sda, uint8_t pin_scl) { #endif int error; uint8_t c; #if defined __AVR__ Wire.begin(); #else _pin_sda = pin_sda; _pin_scl = pin_scl; // Initialize the 'Wire' class for I2C-bus communication. Wire.begin(_pin_sda,_pin_scl); #endif // Initialize the MMA7455, and set the offset. error = MMA7455_init(); if (error == 0) Serial.println("The MMA7455 is okay"); else Serial.println("Check your wiring !"); // Read the Status Register MMA7455_read(MMA7455_STATUS, &c, 1); // Read the "Who am I" value MMA7455_read(MMA7455_WHOAMI, &c, 1); // Read the optional temperature output value (I always read zero) MMA7455_read(MMA7455_TOUT, &c, 1); }
int main() // Main function { MMA7455_init(DATA, CLK, ENABLE); MMA7455_setOffsetX(0); MMA7455_setOffsetY(0); MMA7455_setOffsetZ(0); while(1) // Main loop { signed char x, y, z; MMA7455_gRange(2); MMA7455_getxyz8(&x, &y, &z); print("%c Bits = 8, Range = 2 g, +/- 1 g = +/- 64\n", // Display measurements HOME); print(" x = %d, y = %d, z = %d %c \n", // Display measurements x, y, z, CLREOL); MMA7455_gRange(4); MMA7455_getxyz8(&x, &y, &z); print(" Bits = 8, Range = 4 g, +/- 1 g = +/- 32\n"); print(" x = %d, y = %d, z = %d %c \n", // Display measurements x, y, z, CLREOL); MMA7455_gRange(8); MMA7455_getxyz8(&x, &y, &z); print(" Bits = 8, Range = 8 g, +/- 1 g = +/- 16\n"); print(" x = %d, y = %d, z = %d %c \n", // Display measurements x, y, z, CLREOL); signed short xs, ys, zs; MMA7455_getxyz10(&xs, &ys, &zs); print(" Bits = 10, Range = 8 g, +/- 1 g = +/- 64\n"); print(" x = %d, y = %d, z = %d %c \n", // Display measurements xs, ys, zs, CLREOL); pause(500); // Wait 0.5 s before repeat } }