private static void DisplaySpeedTest(LiquidCrystal lc) { lc.Clear(); long i = -1; while(i++ < 1000) { lc.Clear(); //lc.SetCursor(0, 0); var date = DateTime.Now.ToString("s"); date = date.Substring(0, date.IndexOf("T")); switch (i % 2) { case 0 :_liquidCrystal.PrintRightPadded("[{0}] {1}", i.ToString("00"), DateTime.Now.ToString("T").Replace(" ","")); break; case 1 :_liquidCrystal.Print("[{0}] {1}", i.ToString("00"), date);break; } lc.SetCursor(0, 1); switch (i % 3) { case 0 : var cpuInfo = _machineInfo.CpuPercent.NextValue().ToString("0.00");_liquidCrystal.PrintRightPadded("Cpu {0}%", cpuInfo); break; case 1 :_liquidCrystal.PrintRightPadded("DiskR {0}Mb/s", (_machineInfo.DiskReadBytePerSec.NextValue()/1024/1024).ToString("0.00")); break; case 2 :_liquidCrystal.PrintRightPadded("DiskW {0}Mb/s", (_machineInfo.DiskWriteBytePerSec.NextValue()/1024/1024).ToString("0.00")); break; } TimePeriod.Sleep(1000); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; break; } } }
public static void Run(string[] args) { Console.WriteLine("Nusbio initialization"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); int counter = 0; _machineInfo = new MachineInfo(); var secondTimeOut = new TimeOut(1000); _liquidCrystal = new LiquidCrystal(nusbio, rs:0, enable:1, d0:2, d1:3, d2:4, d3:5); _liquidCrystal.Begin(16, 2); _liquidCrystal.Clear(); while(nusbio.Loop()) { if (secondTimeOut.IsTimeOut()) { counter++; DisplayTime(_liquidCrystal); if(counter % 5 ==0) NusbioRocks(_liquidCrystal); if(counter % 8 ==0) ProgressBarDemo(_liquidCrystal); } if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.D) { DisplaySpeedTest(_liquidCrystal); _liquidCrystal.Clear(); } if (k == ConsoleKey.A) { ApiDemo(_liquidCrystal); _liquidCrystal.Clear(); } if (k == ConsoleKey.C) { CustomCharDemo(_liquidCrystal); _liquidCrystal.Clear(); } if (k == ConsoleKey.F) { Cls(nusbio); } if (k == ConsoleKey.Q) { _liquidCrystal.Clear(); break; } Cls(nusbio); } } } Console.Clear(); }
private static void NusbioRocks(LiquidCrystal lc) { var autoScrollDemoText1 = "Nusbio for .NET rocks or what?"; lc.Clear(); lc.Autoscroll(); lc.SetCursor(15, 0); try { foreach (var c in autoScrollDemoText1) { lc.Print(c.ToString()); TimePeriod.Sleep(180); if (Console.KeyAvailable) return; } TimePeriod.Sleep(1000); } finally{ lc.NoAutoscroll(); lc.Clear(); } }
private static void ProgressBarDemo(LiquidCrystal lc) { lc.Clear(); lc.Print(0, 0, "Working hard..."); for (var p = 0; p <= 100; p += 10) { lc.ProgressBar(0, 1, 10, p, string.Format("{0}% ", p.ToString("000"))); TimePeriod.Sleep(150); if (Console.KeyAvailable) { lc.Clear(); return; } } TimePeriod.Sleep(1000); lc.Clear(); }
private static void CustomCharDemo(LiquidCrystal lc) { var smiley = new List<string>() { "B00000", "B10001", "B00000", "B00000", "B10001", "B01110", "B00000", "B00000", }; lc.CreateChar(0, BitUtil.ParseBinary(smiley).ToArray()); lc.Clear(); lc.Write(0); lc.Write(0xF4); lc.Write(0xFF); lc.Write(0xFF); var k = Console.ReadKey(); }
private static void ApiDemoDisplay(LiquidCrystal lc, int x, int y, string text, bool clear = true, int waitTime = 1000) { if(clear) lc.Clear(); if(text.Length > 16) { var p = 15; while (p > 0 & text[p] != ' ') { p--; } if(p==0) p = 15; lc.Print(x, y, text.Substring(0, p)); lc.Print(x, y+1, text.Substring(p).TrimStart()); } else { lc.Print(x, y, text); } if(waitTime> 0) TimePeriod.Sleep(waitTime); }