Created
August 15, 2011 12:40
-
-
Save TAUTIC/1146147 to your computer and use it in GitHub Desktop.
MMA7660FCR1 Example Code - For ChipKit UNO32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
void setup() | |
{ | |
Serial.begin(38400); // start serial for output | |
Wire.begin(); | |
} | |
void loop() | |
{ | |
delay(10); | |
Wire.beginTransmission(0x4C); //Set MMA7660FCR1 to active mode | |
Wire.send(0x07); | |
Wire.send(0x01); | |
Wire.endTransmission(); | |
delay(100); | |
char x,y,z,tilt,sample,mode,fac; | |
while(1) | |
{ | |
unsigned char val; | |
Wire.beginTransmission(0x4C); | |
Wire.send(0x00); // register to read | |
Wire.endTransmission(); | |
Wire.requestFrom(0x4C, 11); // read a byte | |
while(!Wire.available()) { } // wait for data | |
x = Wire.receive(); | |
y = Wire.receive(); | |
z = Wire.receive(); | |
tilt = Wire.receive(); | |
sample = Wire.receive(); | |
Wire.receive(); //throw away byte | |
Wire.receive(); //throw away byte | |
mode = Wire.receive(); | |
Wire.receive(); //throw away byte | |
Wire.receive(); //throw away byte | |
Wire.receive(); //throw away byte | |
fac = Wire.receive(); | |
Serial.print("X="); | |
Serial.print(x, DEC); | |
Serial.print(", Y="); | |
Serial.print(y, DEC); | |
Serial.print(", Z="); | |
Serial.print(z, DEC); | |
Serial.print(", Mode="); | |
Serial.print(mode,DEC); | |
Serial.print(", Tilt="); | |
Serial.print(tilt,DEC); | |
Serial.print(", sample="); | |
Serial.print(sample,DEC); | |
Serial.print(", fac="); | |
Serial.print(fac,DEC); | |
Serial.println("."); | |
delay(100); | |
} | |
} | |
void wrReg(unsigned char reg, unsigned char val) | |
{ | |
Wire.beginTransmission(0x4C); | |
Wire.send(reg); | |
Wire.send(val); | |
Wire.endTransmission(); | |
} | |
unsigned char rdReg(unsigned char reg) | |
{ | |
unsigned char val; | |
Wire.beginTransmission(0x4C); | |
Wire.send(reg); // register to read | |
Wire.endTransmission(); | |
digitalWrite(A4, HIGH); | |
delay(5); | |
digitalWrite(A4, LOW); | |
delay(5); | |
Wire.requestFrom(0x4C, 1); // read a byte | |
while(!Wire.available()) { } // wait for data | |
return Wire.receive(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment