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@4:3618abce1646, 2022-04-21 (annotated)
- Committer:
- vitpetrik
- Date:
- Thu Apr 21 13:19:41 2022 +0000
- Revision:
- 4:3618abce1646
Share for Stepan Oslejsek
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| vitpetrik | 4:3618abce1646 | 1 | #include "mbed.h" |
| vitpetrik | 4:3618abce1646 | 2 | #include "SSD1306_mini.h" |
| vitpetrik | 4:3618abce1646 | 3 | #include "MMC5883L.h" |
| vitpetrik | 4:3618abce1646 | 4 | |
| vitpetrik | 4:3618abce1646 | 5 | SSD1306_mini_swspi gOled1(PA_5, PA_7,PA_3,PA_4,PA_2); |
| vitpetrik | 4:3618abce1646 | 6 | // SSD1306_mini_swspi(PinName D0, PinName D1, PinName DC, PinName RST, PinName CS) |
| vitpetrik | 4:3618abce1646 | 7 | |
| vitpetrik | 4:3618abce1646 | 8 | MMC5883L compass(PF_0, PF_1); |
| vitpetrik | 4:3618abce1646 | 9 | |
| vitpetrik | 4:3618abce1646 | 10 | int main() { |
| vitpetrik | 4:3618abce1646 | 11 | |
| vitpetrik | 4:3618abce1646 | 12 | wait(0.1f); |
| vitpetrik | 4:3618abce1646 | 13 | compass.init(); |
| vitpetrik | 4:3618abce1646 | 14 | wait(0.1f); |
| vitpetrik | 4:3618abce1646 | 15 | int16_t data[3] = {0,0,0}; |
| vitpetrik | 4:3618abce1646 | 16 | |
| vitpetrik | 4:3618abce1646 | 17 | while(1) { |
| vitpetrik | 4:3618abce1646 | 18 | double heading = compass.getHeadingXY(data); |
| vitpetrik | 4:3618abce1646 | 19 | double Btot = sqrt(pow((double)data[0],2) + pow((double)data[1],2) + pow((double)data[2],2)); |
| vitpetrik | 4:3618abce1646 | 20 | |
| vitpetrik | 4:3618abce1646 | 21 | |
| vitpetrik | 4:3618abce1646 | 22 | int16_t compassRadius = gOled1.height()/2-1; |
| vitpetrik | 4:3618abce1646 | 23 | int16_t compassCenterX = gOled1.width()/2; |
| vitpetrik | 4:3618abce1646 | 24 | int16_t compassCenterY = gOled1.height()/2; |
| vitpetrik | 4:3618abce1646 | 25 | |
| vitpetrik | 4:3618abce1646 | 26 | gOled1.clearDisplay(); |
| vitpetrik | 4:3618abce1646 | 27 | char str[20]; |
| vitpetrik | 4:3618abce1646 | 28 | |
| vitpetrik | 4:3618abce1646 | 29 | int32_t xyz_nt[3]; |
| vitpetrik | 4:3618abce1646 | 30 | compass.getXYZ_OffsetRemoved_nT(xyz_nt); |
| vitpetrik | 4:3618abce1646 | 31 | |
| vitpetrik | 4:3618abce1646 | 32 | gOled1.setTextCursor(0, 5); |
| vitpetrik | 4:3618abce1646 | 33 | |
| vitpetrik | 4:3618abce1646 | 34 | gOled1.printf("X: %i", xyz_nt[0]);; |
| vitpetrik | 4:3618abce1646 | 35 | |
| vitpetrik | 4:3618abce1646 | 36 | gOled1.setTextCursor(0, 15); |
| vitpetrik | 4:3618abce1646 | 37 | |
| vitpetrik | 4:3618abce1646 | 38 | gOled1.printf("Y: %i", xyz_nt[1]); |
| vitpetrik | 4:3618abce1646 | 39 | |
| vitpetrik | 4:3618abce1646 | 40 | gOled1.setTextCursor(0, 25); |
| vitpetrik | 4:3618abce1646 | 41 | |
| vitpetrik | 4:3618abce1646 | 42 | gOled1.printf("Z: %i", xyz_nt[2]); |
| vitpetrik | 4:3618abce1646 | 43 | |
| vitpetrik | 4:3618abce1646 | 44 | |
| vitpetrik | 4:3618abce1646 | 45 | /* |
| vitpetrik | 4:3618abce1646 | 46 | gOled1.printf("MMC5883 kompas\r\n"); |
| vitpetrik | 4:3618abce1646 | 47 | |
| vitpetrik | 4:3618abce1646 | 48 | |
| vitpetrik | 4:3618abce1646 | 49 | gOled1.drawCircle(compassCenterX, compassCenterY, compassRadius, WHITE ); |
| vitpetrik | 4:3618abce1646 | 50 | gOled1.fillCircle(compassCenterX, compassCenterY, 2, WHITE ); |
| vitpetrik | 4:3618abce1646 | 51 | |
| vitpetrik | 4:3618abce1646 | 52 | gOled1.drawLine(compassCenterX, compassCenterY+18, compassCenterX, compassCenterY+20, WHITE); |
| vitpetrik | 4:3618abce1646 | 53 | gOled1.drawLine(compassCenterX, compassCenterY-18, compassCenterX, compassCenterY-20, WHITE); |
| vitpetrik | 4:3618abce1646 | 54 | gOled1.drawLine(compassCenterX+18, compassCenterY, compassCenterX+20, compassCenterY, WHITE); |
| vitpetrik | 4:3618abce1646 | 55 | gOled1.drawLine(compassCenterX-18, compassCenterY, compassCenterX-20, compassCenterY, WHITE); |
| vitpetrik | 4:3618abce1646 | 56 | |
| vitpetrik | 4:3618abce1646 | 57 | double x_vect = cos(heading)* compassRadius; |
| vitpetrik | 4:3618abce1646 | 58 | double y_vect = sin(heading)* compassRadius; |
| vitpetrik | 4:3618abce1646 | 59 | |
| vitpetrik | 4:3618abce1646 | 60 | gOled1.drawLine(compassCenterX, compassCenterY, (int16_t) (compassCenterX + x_vect), (int16_t) (compassCenterY - y_vect), WHITE); |
| vitpetrik | 4:3618abce1646 | 61 | |
| vitpetrik | 4:3618abce1646 | 62 | gOled1.setTextCursor(compassCenterX-2, compassCenterY-compassRadius); |
| vitpetrik | 4:3618abce1646 | 63 | gOled1.printf("S"); |
| vitpetrik | 4:3618abce1646 | 64 | gOled1.setTextCursor(compassCenterX-2, compassCenterY+compassRadius-7); |
| vitpetrik | 4:3618abce1646 | 65 | gOled1.printf("J"); |
| vitpetrik | 4:3618abce1646 | 66 | gOled1.setTextCursor(compassCenterX-compassRadius-2, compassCenterY-3); |
| vitpetrik | 4:3618abce1646 | 67 | gOled1.printf("Z"); |
| vitpetrik | 4:3618abce1646 | 68 | gOled1.setTextCursor(compassCenterX+compassRadius-2, compassCenterY-3); |
| vitpetrik | 4:3618abce1646 | 69 | gOled1.printf("V"); |
| vitpetrik | 4:3618abce1646 | 70 | |
| vitpetrik | 4:3618abce1646 | 71 | gOled1.setTextCursor(0, gOled1.height()-18); |
| vitpetrik | 4:3618abce1646 | 72 | gOled1.printf("FEL"); |
| vitpetrik | 4:3618abce1646 | 73 | gOled1.setTextCursor(17*6, gOled1.height()-18); |
| vitpetrik | 4:3618abce1646 | 74 | gOled1.printf("CVUT"); |
| vitpetrik | 4:3618abce1646 | 75 | |
| vitpetrik | 4:3618abce1646 | 76 | gOled1.setTextCursor(0, gOled1.height()-8); |
| vitpetrik | 4:3618abce1646 | 77 | gOled1.printf("LPE"); |
| vitpetrik | 4:3618abce1646 | 78 | gOled1.setTextCursor(17*6, gOled1.height()-8); |
| vitpetrik | 4:3618abce1646 | 79 | gOled1.printf("2021"); |
| vitpetrik | 4:3618abce1646 | 80 | // } */ |
| vitpetrik | 4:3618abce1646 | 81 | gOled1.display(); |
| vitpetrik | 4:3618abce1646 | 82 | wait(0.05f); |
| vitpetrik | 4:3618abce1646 | 83 | } |
| vitpetrik | 4:3618abce1646 | 84 | } |
| vitpetrik | 4:3618abce1646 | 85 |