Last active
August 12, 2022 21:18
-
-
Save hatsunea/924dce9b2a87b13af12e1093b7f72aa9 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 nanoFramework.M5Stack; | |
using nanoFramework.Presentation.Media; | |
using System; | |
using System.Threading; | |
using Console = nanoFramework.M5Stack.Console; | |
namespace M5StickCScreenWriteSample | |
{ | |
/// <summary> | |
/// 解像度135(x) x 240(y) | |
/// </summary> | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Setup(); | |
Loop(); | |
} | |
private static void Setup() | |
{ | |
M5StickCPlus.AccelerometerGyroscope.Calibrate(100); | |
M5StickCPlus.InitializeScreen(); | |
Console.Clear(); | |
} | |
private static void Loop() | |
{ | |
var y = new ushort[120]; | |
var blue16bit = new ushort[] { ColorUtility.To16Bpp(Color.Blue) }; | |
while (true) | |
{ | |
Console.Clear(); | |
for (ushort x = 0; x < 120; x++) | |
{ | |
var accelerometer = M5StickCPlus.AccelerometerGyroscope.GetAccelerometer(); | |
var az = accelerometer.Z * 1000; | |
Console.CursorTop = 0; | |
Console.WriteLine($"z={accelerometer.Z:F3} G"); | |
y[x] = Map((int)az, 0, 2000, 240); | |
if (x == 0) continue; | |
for (int lineY = Math.Min(y[x - 1], y[x]); lineY <= Math.Min(y[x - 1], y[x]); lineY++) | |
{ | |
Screen.Write((ushort)(x + 5), (ushort)lineY, 1, 1, blue16bit); | |
} | |
Thread.Sleep(20); | |
} | |
} | |
} | |
private static ushort Map(int value, int minValue, int maxValue, int screenHeigh) | |
{ | |
var returnValue = (((value - minValue) * screenHeigh) / (maxValue - minValue)); | |
if (returnValue < 0) returnValue = 0; | |
if (returnValue >= screenHeigh) returnValue = screenHeigh - 1; | |
return (ushort)returnValue; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment