Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the U8g2 library
- #include <Arduino.h>
- #include <U8g2lib.h>
- #include <QMC5883LCompass.h>
- #ifdef U8X8_HAVE_HW_SPI
- #include <SPI.h>
- #endif
- #ifdef U8X8_HAVE_HW_I2C
- #include <Wire.h>
- #endif
- // Initialize a U8g2 display object for a 128x64 OLED display with I2C interface
- //U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
- //U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
- //U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /reset=/ U8X8_PIN_NONE);
- U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, /*clock=*/ 9, /*data=*/ 10, /*reset=*/ U8X8_PIN_NONE);
- QMC5883LCompass compass;
- int angle = 0;
- // The setup function runs once when the program starts
- void setup() {
- Serial.begin(9600);
- u8g2.begin(); // Initialize the display
- u8g2.setContrast(255); // Set display contrast to maximum
- u8g2.setFont(u8g2_font_ncenB08_tr); // Set the font to use for displaying text
- compass.init();
- compass.read();
- //{
- // u8g2.clearBuffer(); // Clear the display buffer
- // u8g2.setCursor(60 , 40); // Set the cursor position for text
- // u8g2.print(counter); // Print the current count value to the display
- // u8g2.sendBuffer(); // Send the buffer to the display to update the display
- // }
- }
- // The loop function runs repeatedly while the program is running
- void loop() {
- angle = compass.getAzimuth();
- Serial.println(angle);
- // Read compass values
- compass.read();
- //Serial.println(angle);
- u8g2.clearBuffer(); // Clear the display buffer
- u8g2.setFont(u8g2_font_ncenB08_tr);
- // Set the cursor position for text
- //aa = String(angle);
- if (angle >= 190 && angle <= 210) {
- u8g2.drawStr(1, 10, " OK");
- //u8g2.setCursor(30 , 40);
- //u8g2.print(angle); // Print the current count value to the display
- }
- else {
- u8g2.drawStr(1, 10, "Error"); // Print the current count value to the display
- //u8g2.setCursor(30 , 40);
- //u8g2.print(angle); // Print the current count value to the display
- }
- u8g2.sendBuffer();
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement