bma020.pde
来自「基于arduino的BMA020采集」· PDE 代码 · 共 62 行
PDE
62 行
#include <Wire.h>#define ACCELEROMETER 0x38 #define X_OUT1 0x02 #define X_OUT2 0x03#define Y_OUT1 0x04 #define Y_OUT2 0x05#define Z_OUT1 0x06 #define Z_OUT2 0x07void setup() { Wire.begin(); Serial.begin(9600);}void loop() { short temp; temp=accRead(X_OUT2); temp<<=8; temp|=accRead(X_OUT1); temp=temp>>6; Serial.print("X: "); Serial.print(temp, DEC); Serial.print (" "); temp=accRead(Y_OUT2); temp<<=8; temp|=accRead(Y_OUT1); temp=temp>>6; Serial.print("Y: "); Serial.print(temp, DEC); Serial.print (" "); temp=accRead(Z_OUT2); temp<<=8; temp|=accRead(Z_OUT1); temp=temp>>6; Serial.print("Z: "); Serial.print(temp, DEC); Serial.println(); delay(100);}byte accRead(byte address){ byte val = 0x00; Wire.beginTransmission(ACCELEROMETER); Wire.send(address); Wire.endTransmission(); Wire.requestFrom(ACCELEROMETER, 1); val = Wire.receive(); Wire.endTransmission(); return val;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?