arduinomma7455数据读取 mma7455l低功耗

#include <Wire.h>

const char addr = 0x1d; //the mma7455 address


//char modeselect = 1;//0:Serial Test,1:VitualColorMixer,2:distancemeasure
//byte x1=0;
float x,y,z,x_measure,y_measure,z_measure,easing=0.1;

void accewrite(byte reg,byte data){
Wire.beginTransmission(addr); // transmit todevice
Wire.send(reg);// sets register pointer to the command register
Wire.send(data);// send the data
Wire.endTransmission();// end the transmission
}

byte acceread(byte reg,char command){ //command 1 display:theregister 0x??(reg) value: ??(reading) with"/n"
//command 2 display: ??(reading)
//the other no display
byte reading= 0;
Wire.beginTransmission(addr);// transmit to device
Wire.send(reg);// sets register pointer to the command register
arduinomma7455数据读取 mma7455l低功耗
Wire.endTransmission();// end the transmission
Wire.requestFrom(addr,1);// request 1 bytes from slave device
if(1<=Wire.available()){// if 1 byte was received ( ACK )
reading = Wire.receive(); //receive the register data from slave
// reading = Wire.receive(); // receive the next register data fromslave
}

returnreading;
}

void acceinit(){
accewrite(0x16,0x04);//set theacce to standy mode In standby mode the device can read
// and write to the registers with the I2C/SPI available,
// but no new measurements can be taken in this mode as allcurrent
//consuming parts are off.
accewrite(0x10,0x08); // set x offset value ,x =-1 ,offset = 2
accewrite(0x11,0x00); //the ture x is negative,offset must be positive
accewrite(0x12,0x26); // the same as x
accewrite(0x13,0x00);
// accewrite(0x14,0x28); //Idon't know why z can't offset
// accewrite(0x15,0x04);
accewrite(0x16,0x05); // setthe acce to measure mode : +/- 2g mode, 64 LSB/gOR 0.015625 g/LSB
}

void setup(){
x = y = z =x_measure = y_measure = z_measure = 0;
Wire.begin();// join i2c bus (address optional for master)
Serial.begin(9600); // start serial communicationat 9600bps
acceinit();
}

void loop(){
//test withprocessing:VirtualColorMixer
x_measure= acceread(0x06,0); //read x axis value
y_measure= acceread(0x07,0); //read y axis value
z_measure= acceread(0x08,0); //read z axis value
// x += (x_measure - x ) * easing;
// y += (y_measure - y ) * easing;
// z += ( z_measure - z ) *easing;
Serial.print(x_measure);
Serial.print(",");
Serial.println(y_measure);
//Serial.print(",");
//Serial.println(z);

delay(20);
}

改来改去的,一会要传给Processing,一会自己测试,最后删了一些,留下基本的数据读取。

  

爱华网本文地址 » http://www.413yy.cn/a/25101016/321927.html

更多阅读

iOS8 AirDrop怎么用 airdrop怎么打开

iOS8 AirDrop怎么用——简介AirDrop 是苹果在 iOS7 系统中推出的一个新功能,利用手机上的低功耗蓝牙来传输文件。当然在 iOS8 上也可以使用 AirDrop 功能,与他人分享照片,文件等。下面简单介绍下怎么在 iOS8 上使用 AirDrop 的操作方法

怎么测显卡温度 低功耗1156处理器

怎么测显卡温度——简介测量显卡温度,凡事对电脑知识略懂的人都知道,显卡的发热量是电脑硬件中最大的。普通情况下显卡的温度是在30℃-80℃左右(指非特殊气温或温度高的环境),您比如说,夏天一般室外温度都有达到35度以上,那么显卡温度通常

了解硬盘工作原理 硬盘工作原理动画

BT和迅雷到底伤不伤硬盘,看了你就知道先引用一下某人的话,有人认为BT和迅雷伤害硬盘:为什么频繁读写会损坏硬盘呢?磁头寿命是有限的,频繁的读写会加快磁头臂及磁头电机的磨损,频繁的读写磁盘某个区域更会使该区温度升高,将影响该区磁介质

DZ论坛移动后用户头像不显示的解决办法 dz论坛头像包

我用个DZ论坛,从一个服务器上,移到了另一个服务器上,用户登录上去,数据读取无误,但是会员头像处,不能显示,打叉!登录后台,发现点击“UCenter”不能显示,提示“Not Found。。。”错误!无所谓,不能用“UCenter”无非是有些数据(如改用户名什么的)改

MATLAB中提升小波变换 图像小波变换 matlab

传统的第一代小波变换是在欧式空间内通过基底的平移和伸缩构造小波基的,不适合非欧式空间的应用。因此小波的提升方案应运而生,它是构造第二代小波变换的理想方法。提升的形式给出了小波完全的空间域的完全解释,它具有许多优良的特性:结

声明:《arduinomma7455数据读取 mma7455l低功耗》为网友旧人序分享!如侵犯到您的合法权益请联系我们删除