Last active
August 12, 2022 21:19
-
-
Save hatsunea/10b75b4ece9c9d983baa335363f6da48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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