/BMP280Sample.Program.cs Secret
Created
June 25, 2022 12:22
Star
You must be signed in to star a gist
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 Iot.Device.Bmxx80; | |
using nanoFramework.M5Stack; | |
using nanoFramework.Presentation.Media; | |
using System; | |
using System.Threading; | |
using Console = nanoFramework.M5Stack.Console; | |
namespace BMP280Sample | |
{ | |
public class Program | |
{ | |
private static Bmp280 Bmp; | |
public static void Main() | |
{ | |
try | |
{ | |
Setup(); | |
Loop(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine($"Could not find a valid BMP280 sensor, check wiring! {ex.Message}"); | |
} | |
} | |
private static void Setup() | |
{ | |
M5Core2.InitializeScreen(); | |
Console.Clear(); | |
Console.ForegroundColor = Color.White; | |
Console.WriteLine("ENV.II Unit test..."); | |
// PORT A (i2C) | |
Bmp = new Bmp280(M5Core2.GetI2cDevice(0x76)) | |
{ | |
TemperatureSampling = Sampling.LowPower, | |
PressureSampling = Sampling.UltraHighResolution, | |
}; | |
} | |
private static void Loop() | |
{ | |
while (true) | |
{ | |
UnitsNet.Pressure pressure; | |
if (Bmp.TryReadPressure(out pressure)) | |
{ | |
Console.CursorTop = 0; | |
Console.CursorLeft = 0; | |
Console.ForegroundColor = Color.White; | |
Console.BackgroundColor = Color.Black; | |
Console.WriteLine($"DateTime:{DateTime.UtcNow:yyyyMMdd HHmmss}"); | |
Console.WriteLine($"Pressure:{pressure.Hectopascals:F}hPa"); | |
Thread.Sleep(1000); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment