Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Last active August 12, 2022 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hatsunea/10b75b4ece9c9d983baa335363f6da48 to your computer and use it in GitHub Desktop.
Save hatsunea/10b75b4ece9c9d983baa335363f6da48 to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using System.Threading;
using Iot.Device.Mpu6886;
using nanoFramework.M5Stack;
using Console = nanoFramework.M5Stack.Console;
namespace M5StickCMpu6886Sample
{
public class Program
{
private static bool IsCalibrating = false;
public static void Main()
{
Setup();
Loop();
}
private static void Setup()
{
M5StickCPlus.InitializeScreen();
Console.ForegroundColor = nanoFramework.Presentation.Media.Color.White;
Calibrating();
M5StickCPlus.ButtonM5.Press += (s, e) =>
{
Calibrating();
};
}
private static void Calibrating()
{
WriteLine("Start calibration ...");
IsCalibrating = true;
M5StickCPlus.AccelerometerGyroscope.Calibrate(100);
IsCalibrating = false;
WriteLine("Ended calibration ...");
}
private static void Loop()
{
while (true)
{
if (!IsCalibrating)
{
var accelerometer = M5StickCPlus.AccelerometerGyroscope.GetAccelerometer();
var gyroscope = M5StickCPlus.AccelerometerGyroscope.GetGyroscope();
Console.CursorTop = 0;
WriteLine($" ---X--- ---Y--- ---Z---");
WriteLine($"Acc {accelerometer.X:F4} {accelerometer.Y:F4} {accelerometer.Z:F4}");
WriteLine($"Gyr {gyroscope.X:F4} {gyroscope.Y:F4} {gyroscope.Z:F4}");
}
Thread.Sleep(500);
}
}
private static void WriteLine(string s)
{
Debug.WriteLine(s);
Console.WriteLine(s);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment