?? bma020.pde
字號:
#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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -