Skip to content
Snippets Groups Projects
Commit 27b81048 authored by ajk1e20's avatar ajk1e20
Browse files

Upload New File

parent 9b5d1857
Branches
No related tags found
No related merge requests found
#include <stdio.h>
#include "pico/stdlib.h"
#include "lib/fonts.h"
#include "lib/st7735.h"
#include "lib/ICM20948.h"
// Based off the helpful guide from plaaosert (ct2g20)
void SetupIMU() {
// Apparently this is important ¯\_(ツ)_/¯
i2c_init(i2c0, 400 * 1000);
gpio_set_function(4, GPIO_FUNC_I2C);
gpio_set_function(5, GPIO_FUNC_I2C);
gpio_pull_up(4);
gpio_pull_up(5);
sleep_ms(1000);
IMU_EN_SENSOR_TYPE enMotionSensorType;
imuInit(&enMotionSensorType);
if (IMU_EN_SENSOR_TYPE_ICM20948 != enMotionSensorType) {
printf("Failed to initialise IMU...");
}
printf("IMU initialised!");
}
int main() {
stdio_init_all(); // Initialise serial in/output
setvbuf ( stdout , NULL , _IONBF , 0 ); // Disable line and block buffering on stdout (for serial comm.)
sleep_ms(1000);
ST7735_Init();
ST7735_FillScreen(ST7735_BLACK);
SetupIMU();
// TODO: initialize variables
float tmp_x = 0.0f;
float tmp_y = 0.0f;
float tmp_z = 0.0f;
char xString[5];
char yString[5];
char zString[5];
while (true) {
// TODO: read from IMU
icm20948MagRead(&tmp_x, &tmp_y, &tmp_z);
sprintf(xString, "%.1f", tmp_x );
sprintf(yString, "%.1f", tmp_y );
sprintf(zString, "%.1f", tmp_z );
// TODO: draw something to the LCD
ST7735_WriteString(5,20, xString, Font_16x26, ST7735_WHITE, ST7735_BLACK);
ST7735_WriteString(5,45, yString, Font_16x26, ST7735_WHITE, ST7735_BLACK);
ST7735_WriteString(5,65, zString, Font_16x26, ST7735_WHITE, ST7735_BLACK);
sleep_ms(100);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment