MrLunk

Arduino gy271 compass, start and remember 1st heading

Mar 24th, 2021 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <QMC5883LCompass.h>
  2.  
  3. QMC5883LCompass compass;
  4. int Read1stAngle = 0;
  5. int StartAngle = 0;
  6.  
  7. void setup() {
  8. Serial.begin(115200);
  9. compass.init();
  10. }
  11.  
  12. void loop() {
  13.  
  14. int Direction;
  15. char myArray[3];
  16. compass.read();
  17. Direction = compass.getAzimuth();
  18.  
  19. if ( Read1stAngle == 0 ) { //Store start angle
  20. StartAngle = Direction;
  21. Read1stAngle = 1;
  22. }
  23.  
  24. Serial.print("Heading: ");
  25. Serial.print(Direction);
  26. Serial.print(" / StartAngle: ");
  27. Serial.print(StartAngle);
  28. Serial.print(" / Read1stAngle: ");
  29.  
  30. delay(250);
  31. }
Add Comment
Please, Sign In to add comment