SHARE
TWEET

Untitled

a guest Apr 22nd, 2017 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2.  
  3. void setup() {
  4. Serial.begin(38400);
  5. SPI.begin();
  6. pinMode(8, OUTPUT);
  7. digitalWrite(8, HIGH);
  8. }
  9.  
  10. #define SPI_SETTING     SPISettings(2000000, MSBFIRST, SPI_MODE0)
  11.  
  12. void loop() {
  13. SPI.beginTransaction(SPI_SETTING);
  14. digitalWrite(8, LOW);
  15. SPI.transfer(               0b10110001); //z1
  16. int16_t z1 = SPI.transfer16(0b11000001) >> 3; //z2
  17. int16_t z2 = SPI.transfer16(0b11010001) >> 3; //x
  18. int16_t  x = SPI.transfer16(0b11010001) >> 3; //x
  19. int16_t  x2= SPI.transfer16(0b10010001) >> 3; //y
  20. int16_t  y = SPI.transfer16(0b10010001) >> 3; //y
  21. int16_t  y2= SPI.transfer16(0) >> 3;
  22. digitalWrite(8, HIGH);
  23. SPI.endTransaction();
  24. Serial.print(z1);
  25. Serial.print(z2);
  26. Serial.print(x);
  27. Serial.print(x2);
  28. Serial.print(y);
  29. Serial.println(y2);
  30. delay(500);
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top