public static void Main() { _oled = new OLEDCClick(Hardware.SocketOne) { FrameRate = OLEDCClick.FrameRates.OCS_140_4Hz }; _oled.Canvas.Clear(KnownColors.Wheat); _oled.Canvas.DrawText("Hello", _font1, KnownColors.Red, 0, (_oled.CanvasHeight - _font1.FontHeight) / 2, 96, _font1.FontHeight, true); _oled.Flush(); Thread.Sleep(Timeout.Infinite); }
public static void Main() { Debug.GC(true); _oled = new OLEDCClick(Hardware.SocketFour) { FrameRate = OLEDCClick.FrameRates.OCS_140_4Hz }; var img1 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly1)); var img2 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly2)); var img3 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly3)); var img4 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly4)); var img5 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly5)); var img6 = new MikroBitmap(Resources.GetBytes(Resources.BinaryResources.bfly6)); while (true) { _oled.Canvas.DrawImage(img1, (_oled.CanvasWidth - img1.Width) / 2, (_oled.CanvasHeight - img1.Height) / 2); _oled.Flush(); //Debug.GC(true); Thread.Sleep(100); _oled.Canvas.DrawImage(img2, (_oled.CanvasWidth - img2.Width) / 2, (_oled.CanvasHeight - img2.Height) / 2); _oled.Flush(); //Debug.GC(true); Thread.Sleep(100); _oled.Canvas.DrawImage(img3, (_oled.CanvasWidth - img3.Width) / 2, (_oled.CanvasHeight - img3.Height) / 2); _oled.Flush(); //Debug.GC(true); Thread.Sleep(100); _oled.Canvas.DrawImage(img4, (_oled.CanvasWidth - img4.Width) / 2, (_oled.CanvasHeight - img4.Height) / 2); _oled.Flush(); //Debug.GC(true); Thread.Sleep(100); _oled.Canvas.DrawImage(img5, (_oled.CanvasWidth - img5.Width) / 2, (_oled.CanvasHeight - img5.Height) / 2); _oled.Flush(); //Debug.GC(true); Thread.Sleep(100); _oled.Canvas.DrawImage(img6, (_oled.CanvasWidth - img6.Width) / 2, (_oled.CanvasHeight - img6.Height) / 2); _oled.Flush(); Thread.Sleep(100); Debug.GC(true); } }
public static void Main() { try { _oled = new OLEDCClick(Hardware.SocketFour) { FrameRate = OLEDCClick.FrameRates.OCS_140Hz }; } catch (PinInUseException ex) { Debug.Print(ex.Message); } while (true) { _oled.Canvas.Clear(); // Show some intro text Debug.Print("Show some intro text"); _oled.Canvas.DrawText(str1, _font6, KnownColors.Red, 0, 0, 96, _font6.FontHeight, true); _oled.Canvas.DrawText(str2, _font6, KnownColors.Yellow, 0, _font6.FontHeight * 2, 96, _font6.FontHeight, true); _oled.Canvas.DrawText(str3, _font6, KnownColors.Blue, 0, (_font6.FontHeight * 4) - 4, 96, _font6.FontHeight, true); _oled.Flush(); Thread.Sleep(3000); _oled.Canvas.Clear(); _oled.Canvas.DrawText(str4, _font7, KnownColors.White, 0, 20, 96, 36, true); _oled.Canvas.DrawText(str5, _font2, KnownColors.Red, 0, 60, 96, 46, true); _oled.Flush(); Thread.Sleep(3000); // Draw Logo1 Debug.Print("Draw Logo1"); _oled.Canvas.Clear(KnownColors.White); _oled.Canvas.DrawImage(logo, (_oled.CanvasWidth - logo.Width) / 2, (_oled.CanvasHeight - logo.Height) / 2); _oled.Flush(); Thread.Sleep(3000); // Draw an image from and embedded RGB 888 Bitmap and then overlay an image from a byte array over top of it. Debug.Print("Draw an image from and embedded RGB 888 Bitmap and then overlay an image from a byte array over top of it."); using (var bmp = new Bitmap(Resources.GetBytes(Resources.BinaryResources.mbn_logo), Bitmap.BitmapImageType.Bmp)) { _oled.Canvas.Clear(KnownColors.White); var img = bmp.ToMikroBitmap(); _oled.Canvas.DrawImage(img, (_oled.CanvasWidth - bmp.Width) / 2, (_oled.CanvasHeight - bmp.Height) / 2); _oled.Flush(); Thread.Sleep(1000); _oled.Canvas.DrawImage(new MikroBitmap(questionMark), 96 - 24, 96 - 24); _oled.Flush(); } Thread.Sleep(3000); // ScreenSaver Test Debug.Print("ScreenSaver Test"); for (byte x = 0; x < 8; x++) { _oled.StartScreenSaver((OLEDCClick.ScreenSaverMode)x, x == 7 ? (byte)0x02 : (byte)0x00); Thread.Sleep(5000); _oled.StopScreenSaver(); } // Draw some rectangles // Draw Rectangle passing a Rect Structure Debug.Print("Draw Rectangle passing a Rect Structure"); _oled.Canvas.DrawRectangle(KnownColors.Red, KnownColors.Red, new Rect(0, 0, 96, 16)); _oled.Canvas.DrawRectangle(KnownColors.Yellow, KnownColors.Yellow, new Rect(0, 16, 96, 16)); _oled.Canvas.DrawRectangle(KnownColors.Purple, KnownColors.Purple, new Rect(0, 32, 96, 16)); _oled.Canvas.DrawRectangle(KnownColors.Blue, KnownColors.Blue, new Rect(0, 48, 96, 16)); _oled.Canvas.DrawRectangle(KnownColors.DarkSeaGreen, KnownColors.DarkSeaGreen, new Rect(0, 64, 96, 16)); _oled.Canvas.DrawRectangle(KnownColors.CadetBlue, KnownColors.CadetBlue, new Rect(0, 80, 96, 16)); _oled.Flush(); Thread.Sleep(2000); // Draw Rectangle passing X, Y, Width and Height Debug.Print("Draw Rectangle passing X, Y, Width and Height"); _oled.Canvas.DrawRectangle(KnownColors.White, KnownColors.CadetBlue, 0, 0, 16, 96); _oled.Canvas.DrawRectangle(KnownColors.White, KnownColors.DarkSeaGreen, 16, 0, 16, 96); _oled.Canvas.DrawRectangle(KnownColors.White, KnownColors.Blue, 32, 0, 16, 96); _oled.Canvas.DrawRectangle(KnownColors.White, KnownColors.Purple, 48, 0, 16, 96); _oled.Canvas.DrawRectangle(KnownColors.White, KnownColors.Yellow, 64, 0, 16, 96); _oled.Canvas.DrawRectangle(KnownColors.White, KnownColors.PapayaWhip, 80, 0, 16, 96); _oled.Flush(); Thread.Sleep(2000); // Fill the screen with a Random colors a few times Debug.Print("Fill the screen with a Random colors a few times"); for (int x = 0; x < 50; x++) { _oled.Canvas.Clear(GenerateRandomColor()); _oled.Flush(); } // Fill Canvas with gradient Debug.Print("Fill Canvas with gradient"); _oled.Canvas.DrawRectangle(KnownColors.White, 2, KnownColors.Blue, KnownColors.Red, 0, 0, _oled.CanvasWidth, _oled.CanvasHeight, true); _oled.Flush(); Thread.Sleep(1500); // Draw some random Gradients, first 25 horizontally and the next 25 vertically. Debug.Print("Draw some random Gradients, first 25 horizontally and the next 25 vertically."); var vertical = true; for (int x = 0; x < 50; x++) { if (x > 25) { vertical = false; } _oled.Canvas.DrawRectangle(GenerateRandomColor(), 2, GenerateRandomColor(), GenerateRandomColor(), 0, 0, _oled.CanvasWidth, _oled.CanvasHeight, vertical); _oled.Flush(); } // Draw some randomly placed hollow circles Debug.Print("Draw some randomly placed hollow circles"); _oled.Canvas.Clear(); for (int x = 0; x < 50; x++) { var point = GenerateRandomPoint(); var color = GenerateRandomColor(); var radius = GenerateRandomRadius(); _oled.Canvas.DrawEllipse(color, point.X, point.Y, radius, radius); _oled.Flush(); } // Draw some randomly placed filled circles Debug.Print("Draw some randomly placed filled circles"); _oled.Canvas.Clear(); for (int x = 0; x < 50; x++) { var point = GenerateRandomPoint(); var color = GenerateRandomColor(); var radius = GenerateRandomRadius(); _oled.Canvas.DrawEllipse(color, color, point.X, point.Y, radius, radius); _oled.Flush(); } // Draw some randomly placed gradient filled circles Debug.Print("Draw some randomly placed gradient filled circles"); _oled.Canvas.Clear(); for (int x = 0; x < 50; x++) { var point = GenerateRandomPoint(); var color1 = GenerateRandomColor(); var color2 = GenerateRandomColor(); var color3 = GenerateRandomColor(); var radius1 = GenerateRandomRadius(); var radius2 = GenerateRandomRadius(); _oled.Canvas.DrawEllipse(color1, color2, color3, point.X, point.Y, radius1, radius2); _oled.Flush(); } // Draw some randomly placed lines Debug.Print("Draw some randomly placed lines"); _oled.Canvas.Clear(KnownColors.Black); for (int x = 0; x < 100; x++) { var point1 = GenerateRandomPoint(); var point2 = GenerateRandomPoint(); var color = GenerateRandomColor(); _oled.Canvas.DrawLine(color, point1.X, point1.Y, point2.X, point2.Y); _oled.Flush(); } // Draw some randomly place hollow rectangles Debug.Print("Draw some randomly place hollow rectangles"); _oled.Canvas.Clear(KnownColors.Black); for (int x = 0; x < 50; x++) { var point1 = GenerateRandomPoint(); var point2 = GenerateRandomPoint(); var color = GenerateRandomColor(); _oled.Canvas.DrawRectangle(color, point1.X, point1.Y, point2.X, point2.Y); _oled.Flush(); } // Draw some randomly place filled rectangles Debug.Print("Draw some randomly place filled rectangles"); _oled.Canvas.Clear(KnownColors.Black); for (int x = 0; x < 50; x++) { var point1 = GenerateRandomPoint(); var point2 = GenerateRandomPoint(); var color = GenerateRandomColor(); _oled.Canvas.DrawRectangle(color, color, point1.X, point1.Y, point2.X, point2.Y); _oled.Flush(); } // Draw some randomly place gradient filled rectangles Debug.Print("Draw some randomly place gradient filled rectangles"); _oled.Canvas.Clear(KnownColors.Black); vertical = true; for (int x = 0; x < 50; x++) { if (x > 25) { vertical = false; } var point1 = GenerateRandomPoint(); var point2 = GenerateRandomPoint(); var color = GenerateRandomColor(); _oled.Canvas.DrawRectangle(color, color, point1.X, point1.Y, point2.X, point2.Y); _oled.Canvas.DrawRectangle(GenerateRandomColor(), 2, GenerateRandomColor(), GenerateRandomColor(), point1.X, point1.Y, point2.X, point2.Y, vertical); _oled.Flush(); } // Draw some text Debug.Print("Draw some text"); _oled.Canvas.Clear(KnownColors.Black); var color4 = GenerateRandomColor(); var color5 = GenerateRandomColor(); var color6 = GenerateRandomColor(); var color7 = GenerateRandomColor(); var color8 = GenerateRandomColor(); var color9 = GenerateRandomColor(); _oled.Canvas.DrawText("0123AaBb", _font1, color4, 0, 0, 96, _font1.FontHeight); _oled.Canvas.DrawText("0123AaBb", _font2, color5, 0, _font1.FontHeight + 1, 96, _font2.FontHeight); _oled.Canvas.DrawText("0123AaBb", _font3, color6, 0, _font1.FontHeight + _font2.FontHeight + 1, 96, _font3.FontHeight); _oled.Canvas.DrawText("0123AaBb", _font4, color7, 0, _font1.FontHeight + _font2.FontHeight + _font3.FontHeight + 1, 96, _font4.FontHeight); _oled.Canvas.DrawText("0123AaBb", _font5, color8, 0, _font1.FontHeight + _font2.FontHeight + _font3.FontHeight + _font4.FontHeight + 1, 96, _font5.FontHeight); _oled.Canvas.DrawText("0123AaBb", _font6, color9, 0, _font1.FontHeight + _font2.FontHeight + _font2.FontHeight + _font4.FontHeight + _font5.FontHeight + 1, 96, _font6.FontHeight); _oled.Flush(_oled.Canvas); Thread.Sleep(2000); // Draw some text in a rectangle Debug.Print("Draw some text in a rectangle"); var r1 = new Rect(10, 20, 76, 28); var r2 = new Rect(10, r1.Height + r1.Y + 10, 76, 28); _oled.Canvas.Clear(KnownColors.White); _oled.Canvas.DrawRectangle(KnownColors.Red, KnownColors.White, r1); r1 = r1.Inflate(0, 6, 0, 0); _oled.Canvas.DrawText("MikroBus.Net", _font3, KnownColors.Blue, r1, true); _oled.Canvas.DrawRectangle(KnownColors.Red, KnownColors.White, r2); r2 = r2.Inflate(0, 6, 0, 0); _oled.Canvas.DrawText("Rocks", _font4, KnownColors.Blue, r2, true); _oled.Flush(); Thread.Sleep(5000); Debug.GC(true); // just about at the memory limit here. // PowerMode Debug.Print("PowerMode Test"); _oled.Canvas.Clear(); _oled.Canvas.DrawText("PowerMode Test", _font3, KnownColors.White, 0, 0, 96, 48); _oled.Canvas.DrawText("Low Power for 5 secs", _font1, KnownColors.White, 0, 49, 96, 48); _oled.Flush(); Thread.Sleep(5000); _oled.PowerMode = PowerModes.Low; Thread.Sleep(5000); _oled.PowerMode = PowerModes.On; _oled.Canvas.DrawText("PowerMode Test", _font3, KnownColors.White, 0, 0, 96, 48); _oled.Canvas.DrawText("Low Power for 5 secs", _font1, KnownColors.Black, 0, 49, 96, 48); _oled.Canvas.DrawText("Power back On", _font1, KnownColors.White, 0, 49, 96, 48); _oled.Flush(); Thread.Sleep(2000); // Reset Mode Debug.Print("Reset Test"); _oled.Canvas.Clear(); _oled.Canvas.DrawText("Reset Test", _font3, KnownColors.White, 0, 0, 96, 48); _oled.Canvas.DrawText("Reset in 5 secs", _font1, KnownColors.White, 0, 49, 96, 48); _oled.Flush(); Thread.Sleep(5000); _oled.Reset(ResetModes.Hard); _oled.Canvas.DrawText("Reset Test", _font3, KnownColors.White, 0, 0, 95, 48); _oled.Canvas.DrawText("Reset in 5 secs", _font1, KnownColors.Black, 0, 49, 96, 48); _oled.Canvas.DrawText("Resume from reset", _font1, KnownColors.White, 0, 49, 96, 48); _oled.Flush(); Thread.Sleep(2000); // Display On/Off Test Debug.Print("Display On/Off Test"); _oled.Canvas.Clear(); _oled.Canvas.DrawText("Display Off", _font3, KnownColors.White, 0, 0, 96, _font3.FontHeight); _oled.Flush(); Thread.Sleep(2000); _oled.SetDisplayOn(false); Thread.Sleep(1000); _oled.SetDisplayOn(true); _oled.Canvas.DrawText("Display On", _font3, KnownColors.White, 0, _font3.FontHeight + 1, 96, _font3.FontHeight); _oled.Flush(); Thread.Sleep(2000); Debug.Print("Memory - " + Debug.GC(true)); // Now for a really large font? Debug.Print("Now for a really large font"); var numbers = new MikroFont(Resources.GetBytes(Resources.BinaryResources.tahoma_30e)); _oled.Canvas.Clear(); for (int x = 10; x >= 0; x += -1) { _oled.Canvas.Clear(); var sz = numbers.MeasureString(x.ToString()); _oled.Canvas.DrawText(x.ToString(), numbers, KnownColors.LightSkyBlue, ((96 - sz.Width) / 2) - 1, ((96 - sz.Height) / 2) - 1, 96, 96); _oled.Canvas.DrawText(x.ToString(), numbers, KnownColors.Blue, (96 - sz.Width) / 2, (96 - sz.Height) / 2, 96, 96); _oled.Flush(); Thread.Sleep(1000); } numbers = null; Debug.Print("Memory - " + Debug.GC(true)); } }