Advertisement
michi_

Untitled

Jun 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include<Wire.h>
  2. const int MPU=0x68;
  3. int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
  4.  
  5. #include <RCSwitch.h>
  6. RCSwitch mySwitch = RCSwitch();
  7.  
  8. void setup(){
  9. Wire.begin();
  10. Wire.beginTransmission(MPU);
  11. Wire.write(0x6B);
  12. Wire.write(0);
  13. Wire.endTransmission(true);
  14.  
  15.  
  16. Serial.begin(9600);
  17. mySwitch.enableTransmit(2);
  18.  
  19. }
  20. void loop(){
  21. Wire.beginTransmission(MPU);
  22. Wire.write(0x3B);
  23. Wire.endTransmission(false);
  24. Wire.requestFrom(MPU,12,true);
  25. AcX=Wire.read()<<8|Wire.read();
  26. AcY=Wire.read()<<8|Wire.read();
  27. AcZ=Wire.read()<<8|Wire.read();
  28. GyX=Wire.read()<<8|Wire.read();
  29. GyY=Wire.read()<<8|Wire.read();
  30. GyZ=Wire.read()<<8|Wire.read();
  31.  
  32. Serial.print("Accelerometer: ");
  33. Serial.print("X = "); Serial.print(AcX);
  34. Serial.print(" | Y = "); Serial.print(AcY);
  35. Serial.print(" | Z = "); Serial.println(AcZ);
  36.  
  37. Serial.print("Gyroscope: ");
  38. Serial.print("X = "); Serial.print(GyX);
  39. Serial.print(" | Y = "); Serial.print(GyY);
  40. Serial.print(" | Z = "); Serial.println(GyZ);
  41. Serial.println(" ");
  42.  
  43.  
  44.  
  45. mySwitch.send(AcX,24);
  46.  
  47.  
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement