Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "SSD1306_mini.h" 00003 #include "MMC5883L.h" 00004 00005 SSD1306_mini_swspi gOled1(PA_5, PA_7,PA_3,PA_4,PA_2); 00006 // SSD1306_mini_swspi(PinName D0, PinName D1, PinName DC, PinName RST, PinName CS) 00007 00008 MMC5883L compass(PF_0, PF_1); 00009 00010 int main() { 00011 00012 wait(0.1f); 00013 compass.init(); 00014 wait(0.1f); 00015 int16_t data[3] = {0,0,0}; 00016 00017 while(1) { 00018 double heading = compass.getHeadingXY(data); 00019 double Btot = sqrt(pow((double)data[0],2) + pow((double)data[1],2) + pow((double)data[2],2)); 00020 00021 00022 int16_t compassRadius = gOled1.height()/2-1; 00023 int16_t compassCenterX = gOled1.width()/2; 00024 int16_t compassCenterY = gOled1.height()/2; 00025 00026 gOled1.clearDisplay(); 00027 char str[20]; 00028 00029 int32_t xyz_nt[3]; 00030 compass.getXYZ_OffsetRemoved_nT(xyz_nt); 00031 00032 gOled1.setTextCursor(0, 5); 00033 00034 gOled1.printf("X: %i", xyz_nt[0]);; 00035 00036 gOled1.setTextCursor(0, 15); 00037 00038 gOled1.printf("Y: %i", xyz_nt[1]); 00039 00040 gOled1.setTextCursor(0, 25); 00041 00042 gOled1.printf("Z: %i", xyz_nt[2]); 00043 00044 00045 /* 00046 gOled1.printf("MMC5883 kompas\r\n"); 00047 00048 00049 gOled1.drawCircle(compassCenterX, compassCenterY, compassRadius, WHITE ); 00050 gOled1.fillCircle(compassCenterX, compassCenterY, 2, WHITE ); 00051 00052 gOled1.drawLine(compassCenterX, compassCenterY+18, compassCenterX, compassCenterY+20, WHITE); 00053 gOled1.drawLine(compassCenterX, compassCenterY-18, compassCenterX, compassCenterY-20, WHITE); 00054 gOled1.drawLine(compassCenterX+18, compassCenterY, compassCenterX+20, compassCenterY, WHITE); 00055 gOled1.drawLine(compassCenterX-18, compassCenterY, compassCenterX-20, compassCenterY, WHITE); 00056 00057 double x_vect = cos(heading)* compassRadius; 00058 double y_vect = sin(heading)* compassRadius; 00059 00060 gOled1.drawLine(compassCenterX, compassCenterY, (int16_t) (compassCenterX + x_vect), (int16_t) (compassCenterY - y_vect), WHITE); 00061 00062 gOled1.setTextCursor(compassCenterX-2, compassCenterY-compassRadius); 00063 gOled1.printf("S"); 00064 gOled1.setTextCursor(compassCenterX-2, compassCenterY+compassRadius-7); 00065 gOled1.printf("J"); 00066 gOled1.setTextCursor(compassCenterX-compassRadius-2, compassCenterY-3); 00067 gOled1.printf("Z"); 00068 gOled1.setTextCursor(compassCenterX+compassRadius-2, compassCenterY-3); 00069 gOled1.printf("V"); 00070 00071 gOled1.setTextCursor(0, gOled1.height()-18); 00072 gOled1.printf("FEL"); 00073 gOled1.setTextCursor(17*6, gOled1.height()-18); 00074 gOled1.printf("CVUT"); 00075 00076 gOled1.setTextCursor(0, gOled1.height()-8); 00077 gOled1.printf("LPE"); 00078 gOled1.setTextCursor(17*6, gOled1.height()-8); 00079 gOled1.printf("2021"); 00080 // } */ 00081 gOled1.display(); 00082 wait(0.05f); 00083 } 00084 } 00085
Generated on Fri Sep 2 2022 00:57:54 by
1.7.2