Пример #1
0
        void SensorChannelStatusesChanged(object sender, ChannelStatusChangedEventArgs e)
        {
            graphics.Clear();
            graphics.Stroke = 1;

            for (int i = 0; i < e.ChannelStatus.Count; i++)
            {
                int numpadIndex = 0;
                for (int columns = 0; columns < 3; columns++)
                {
                    for (int rows = 3; rows >= 0; rows--)
                    {
                        if (numpadIndex == i)
                        {
                            if (e.ChannelStatus[(Mpr121.Channels)i])
                            {
                                graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, Meadow.Foundation.Color.Cyan, true);
                            }
                            else
                            {
                                graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, true);
                            }
                        }
                        numpadIndex++;
                    }
                }
            }

            graphics.Show();
        }
Пример #2
0
        int BenchRect(int num)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            graphics.Stroke = 1;
            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawRectangle(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), rand.Next(displayHeight), RandColor(), false);
                graphics.Show();
            }
            int empty = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} Rectangle {empty}ms");
            stopWatch.Restart();

            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawRectangle(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), rand.Next(displayHeight), RandColor(), true);
                graphics.Show();
            }
            int filled = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} Rectangle Filled {filled}ms");
            stopWatch.Stop();

            return(empty + filled);
        }
Пример #3
0
        public static void Main()
        {
            var oled    = new SSD1306(0x3c, 400, SSD1306.DisplayType.OLED128x64);
            var display = new GraphicsLibrary(oled);

            display.Clear(true);
            display.DrawLine(0, 30, 80, 60, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawCircle(63, 31, 20, true, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(20, 20, 60, 40);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(30, 10, 50, 40, true, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.CurrentFont = new Font8x8();
            display.DrawText(4, 10, "NETDUINO 3 WiFi");
            display.Show();
            Thread.Sleep(Timeout.Infinite);
        }
Пример #4
0
        void StartBreakoutLoop()
        {
            while (true)
            {
                breakoutGame.Update();

                graphics.Clear(false);

                graphics.DrawCircle(breakoutGame.Ball.X, breakoutGame.Ball.Y, breakoutGame.Ball.Radius, true, true);


                graphics.DrawRectangle(breakoutGame.Paddle.X, breakoutGame.Paddle.Y,
                                       breakoutGame.Paddle.Width, breakoutGame.Paddle.Height,
                                       true);

                for (int i = 0; i < breakoutGame.Blocks.Length; i++)
                {
                    if (breakoutGame.Blocks[i].IsVisible)
                    {
                        graphics.DrawRectangle(breakoutGame.Blocks[i].X, breakoutGame.Blocks[i].Y,
                                               breakoutGame.Blocks[i].Width, breakoutGame.Blocks[i].Height);
                    }
                }

                graphics.Show();
            }
        }
Пример #5
0
        void DrawWatchFace()
        {
            graphics.Clear();
            int hour = 12;
            int xCenter = displayWidth / 2;
            int yCenter = displayHeight / 2;
            int x, y;

            graphics.DrawRectangle(0, 0, displayWidth, displayHeight, Color.White);
            graphics.DrawRectangle(5, 5, displayWidth - 10, displayHeight - 10, Color.White);
            graphics.CurrentFont = new Font12x20();
            graphics.DrawCircle(xCenter, yCenter, 100, WatchBackgroundColor, true);

            for (int i = 0; i < 60; i++)
            {
                x = (int)(xCenter + 80 * Math.Sin(i * Math.PI / 30));
                y = (int)(yCenter - 80 * Math.Cos(i * Math.PI / 30));

                if (i % 5 == 0)
                {
                    graphics.DrawText(
                        hour > 9 ? x - 10 : x - 5, y - 5, hour.ToString(), Color.Black);

                    if (hour == 12)
                    {
                        hour = 1;
                    }
                    else
                    {
                        hour++;
                    }
                }
            }
            graphics.Show();
        }
Пример #6
0
        void UpdateDisplayFancy(float temperature)
        {
            Console.WriteLine("Update display");

            graphics.Clear();

            Console.WriteLine("Draw");

            var primaryColor = Color.FromRgb(238, 243, 189);
            var accentColor  = Color.FromRgb(26, 128, 170);

            var tempText = GetTemperatureString(temperature);

            var xTempPos = graphics.Width / 2 - tempText.Length * 12;


            graphics.DrawCircle(120, 84, 80, accentColor, true);
            graphics.DrawCircle(120, 84, 80, primaryColor);
            graphics.DrawText((int)xTempPos, 70, tempText, primaryColor, GraphicsLibrary.ScaleFactor.X2);

            //draw pressure bar
            int barWidth = (int)(220.0 * sensor.Pressure / Conversions.StandardAtmInPa);

            graphics.DrawRectangle(10, 190, barWidth, 30, accentColor, true);
            graphics.DrawRectangle(10, 190, 220, 30, primaryColor);
            graphics.DrawText(20, 196, GetPressureString(sensor.Pressure), primaryColor);

            Console.WriteLine("Show");
            graphics.Show();
        }
Пример #7
0
        static void UITest()
        {
            display.Clear();

            display.DrawLine(10, 10, 118, 150, Color.OrangeRed);
            display.Show();
            //     Thread.Sleep(500);
            display.DrawLine(118, 10, 10, 150, Color.OrangeRed);
            display.Show();
            //   Thread.Sleep(500);

            display.DrawCircle(64, 64, 25, Color.Purple);
            display.Show();
            //    Thread.Sleep(1000);

            display.DrawRectangle(5, 5, 118, 150, Color.Aquamarine);
            display.Show();
            //     Thread.Sleep(1000);

            display.DrawRectangle(10, 125, 108, 25, Color.Yellow, true);
            display.Show();
            //    Thread.Sleep(1000);

            display.CurrentFont = new Font8x8();
            display.DrawText(4, 10, "NETDUINO 3 WiFi", Color.SkyBlue);
            display.Show();
            Thread.Sleep(Timeout.Infinite);
        }
Пример #8
0
        public void CountDown()
        {
            int y = 30;

            for (int i = 3; i > 0; i--)
            {
                display.DrawRectangle(114, y, 12, 16, Color.Black, true);
                display.DrawText(114, y, $"{i}", Orange);
                display.Show();
            }
            display.DrawRectangle(114, y, 12, 16, Color.Black, true);
        }
Пример #9
0
        public static void Main()
        {
            // SPI constructor
            var oled = new ST7565(chipSelectPin: Pins.GPIO_PIN_D10,
                dcPin: Pins.GPIO_PIN_D8,
                resetPin: Pins.GPIO_PIN_D9,
                spiModule: SPI.SPI_module.SPI1,
                speedKHz: 10000);

            oled.SetContrast(24);
            oled.SetContrast(12);
            oled.SetContrast(0);


            oled.Clear(true);
            oled.InvertDisplay(true);


            oled.Clear(true);
            oled.InvertDisplay(false);

            oled.IgnoreOutOfBoundsPixels = true;

            var display = new GraphicsLibrary(oled);

            display.Clear(true);
            display.DrawLine(0, 0, 60, 28, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawCircle(63, 31, 20, true, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(20, 20, 60, 40);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(30, 10, 50, 40, true, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.CurrentFont = new Font8x8();
            display.DrawText(4, 0, "NETDUINO 3 WiFi");
            display.DrawCircle(64, 32, 16, true, true);
            display.Show();
            Thread.Sleep(Timeout.Infinite);
        }
Пример #10
0
        void DrawShapes()
        {
            Random rand = new Random();

            graphics.Clear(true);

            int radius  = 10;
            int originX = displayWidth / 2;
            int originY = displayHeight / 2;

            for (int i = 1; i < 5; i++)
            {
                graphics.DrawCircle
                (
                    centerX: originX,
                    centerY: originY,
                    radius: radius,
                    color: Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))
                );
                graphics.Show();
                radius += 30;
            }

            int sideLength = 30;

            for (int i = 1; i < 5; i++)
            {
                graphics.DrawRectangle
                (
                    x: (displayWidth - sideLength) / 2,
                    y: (displayHeight - sideLength) / 2,
                    width: sideLength,
                    height: sideLength,
                    color: Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))
                );
                graphics.Show();
                sideLength += 60;
            }

            graphics.DrawLine(0, displayHeight / 2, displayWidth, displayHeight / 2,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.DrawLine(displayWidth / 2, 0, displayWidth / 2, displayHeight,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.DrawLine(0, 0, displayWidth, displayHeight,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.DrawLine(0, displayHeight, displayWidth, 0,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.Show();

            //Thread.Sleep(5000);
        }
Пример #11
0
        void LoadScreen()
        {
            Console.WriteLine("LoadScreen...");

            graphics.Clear(true);

            graphics.Stroke = 1;
            graphics.DrawRectangle(
                x: 0,
                y: 0,
                width: (int)display.Width,
                height: (int)display.Height,
                color: Color.White);
            graphics.DrawRectangle(
                x: 5,
                y: 5,
                width: (int)display.Width - 10,
                height: (int)display.Height - 10,
                color: Color.White);

            graphics.DrawCircle(
                centerX: (int)display.Width / 2,
                centerY: (int)display.Height / 2,
                radius: (int)(display.Width / 2) - 10,
                color: Color.FromHex("#EF7D3B"),
                filled: true);

            DisplayJPG(55, 40);

            graphics.CurrentFont = new Font8x12();

            string textMotion = "MOTION";

            graphics.DrawText(
                (int)(display.Width - textMotion.Length * 16) / 2,
                140,
                textMotion,
                Color.Black,
                GraphicsLibrary.ScaleFactor.X2);

            string textDetector = "DETECTOR";

            graphics.DrawText(
                (int)(display.Width - textDetector.Length * 16) / 2,
                165,
                textDetector,
                Color.Black,
                GraphicsLibrary.ScaleFactor.X2);

            graphics.Show();
        }
Пример #12
0
        void PartialUpdate()
        {
            graphics.Clear(true);
            graphics.DrawRectangle(0, 0, 240, 320, Color.Teal, true);
            //   graphics.Show(0, 0, 240, 10);

            for (uint x = 0; x < 200; x += 20)
            {
                for (uint y = 0; y < 300; y += 20)
                {
                    display.Show(x, y, x + 20, y + 20);
                }
            }
        }
Пример #13
0
    public MeadowApp()
    {
        x = y = 120;

        var config = new SpiClockConfiguration(
            speedKHz: 6000,
            mode: SpiClockConfiguration.Mode.Mode3);

        st7789 = new St7789(
            device: Device,
            spiBus: Device.CreateSpiBus(
                clock: Device.Pins.SCK,
                mosi: Device.Pins.MOSI,
                miso: Device.Pins.MISO,
                config: config),
            chipSelectPin: null,
            dcPin: Device.Pins.D01,
            resetPin: Device.Pins.D00,
            width: 240, height: 240);

        graphics = new GraphicsLibrary(st7789);
        graphics.Clear(true);
        graphics.DrawRectangle(0, 0, 240, 240, Color.White, true);
        graphics.DrawPixel(x, y, Color.Red);
        graphics.Show();

        rotaryX = new RotaryEncoderWithButton(Device,
                                              Device.Pins.A00, Device.Pins.A01, Device.Pins.A02);
        rotaryX.Rotated += RotaryXRotated;

        rotaryY = new RotaryEncoderWithButton(Device,
                                              Device.Pins.D02, Device.Pins.D03, Device.Pins.D04);
        rotaryY.Rotated += RotaryYRotated;
        rotaryY.Clicked += RotaryYClicked;
    }
Пример #14
0
        private void Sensor_ChannelStatusesChanged(object sender, ChannelStatusChangedEventArgs e)
        {
            string pads = string.Empty;

            graphics.Clear();

            for (int i = 0; i < e.ChannelStatus.Count; i++)
            {
                if (e.ChannelStatus[(Mpr121.Channels)i] == true)
                {
                    pads += i + ", ";

                    graphics.DrawRectangle((i % 4) * rectW, (i / 4) * rectH, rectW, rectH, Meadow.Foundation.Color.Cyan, true);
                }
            }

            if (string.IsNullOrEmpty(pads))
            {
                Console.WriteLine("none");
                graphics.DrawText(0, 0, "none", Meadow.Foundation.Color.Cyan);
            }
            else
            {
                Console.WriteLine(pads + "touched");
            }

            graphics.Show();
        }
Пример #15
0
        void UpdateImage(int index, int xOffSet, int yOffSet)
        {
            var jpgData = LoadResource($"level_{index}.jpg");
            var decoder = new JpegDecoder();
            var jpg     = decoder.DecodeJpeg(jpgData);

            int  x = 0;
            int  y = 0;
            byte r, g, b;

            graphics.DrawRectangle(0, 0, 240, 208, Color.White, true);

            for (int i = 0; i < jpg.Length; i += 3)
            {
                r = jpg[i];
                g = jpg[i + 1];
                b = jpg[i + 2];

                graphics.DrawPixel(x + xOffSet, y + yOffSet, Color.FromRgb(r, g, b));

                x++;
                if (x % decoder.Width == 0)
                {
                    y++;
                    x = 0;
                }
            }

            graphics.Show();
        }
Пример #16
0
        void TestDisplay()
        {
            //force a collection
            GC.Collect();

            Console.WriteLine("Draw");


            for (int i = 0; i < 30; i++)
            {
                display.DrawPixel(i, 120 + i, true);
                display.DrawPixel(30 + i, 120 + i, true);
                display.DrawPixel(60 + i, 120 + i, true);
            }

            // Draw with Display Graphics Library
            graphics.CurrentFont = new Font8x8();
            graphics.Clear();
            graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red);
            graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false);
            graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false);

            graphics.DrawText(5, 5, "Meadow F7 SPI", Color.White);
            graphics.Show();
        }
Пример #17
0
        void Initialize()
        {
            Console.WriteLine("Initializing hardware...");

            Console.WriteLine("Initialize SPI bus");

            var config = new SpiClockConfiguration(12000, SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config);

            Console.WriteLine("Initialize display driver instance");

            St7789 display = new St7789(device: Device, spiBus: spiBus,
                                        chipSelectPin: null,
                                        dcPin: Device.Pins.D01,
                                        resetPin: Device.Pins.D00,
                                        width: 240, height: 240);

            Console.WriteLine("Create graphics library");

            canvas = new GraphicsLibrary(display)
            {
                CurrentFont = new Font12x20()
            };
            canvas.DrawRectangle(0, 0, 240, 240, Color.Black, true);
            canvas.Clear(true);

            Console.WriteLine("Initialize distance sensor");
            var i2cBus = Device.CreateI2cBus(I2cBusSpeed.FastPlus);

            distanceSensor = new Vl53l0x(Device, i2cBus);
        }
Пример #18
0
        void ShapeTest()
        {
            graphics.Clear();

            graphics.DrawCircle(60, 60, 20, Color.Purple);
            graphics.DrawRectangle(10, 10, 30, 60, Color.Red);
            graphics.DrawTriangle(20, 20, 10, 70, 60, 60, Color.Green);

            graphics.DrawCircle(90, 60, 20, Color.Cyan, true);
            graphics.DrawRectangle(100, 100, 30, 10, Color.Yellow, true);
            graphics.DrawTriangle(120, 20, 110, 70, 160, 60, Color.Pink, true);

            graphics.DrawLine(10, 120, 110, 130, Color.SlateGray);

            graphics.Show();
        }
Пример #19
0
        void Initialize()
        {
            Console.WriteLine("Initialize hardware...");

            onboardLed = new RgbPwmLed(device: Device,
                                       redPwmPin: Device.Pins.OnboardLedRed,
                                       greenPwmPin: Device.Pins.OnboardLedGreen,
                                       bluePwmPin: Device.Pins.OnboardLedBlue,
                                       3.3f, 3.3f, 3.3f,
                                       Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode);

            var spiBus = Device.CreateSpiBus();

            display = new ZXBox.MeadowApp.Display.Ssd1351(
                device: Device,
                spiBus: spiBus,
                chipSelectPin: Device.Pins.D00,
                dcPin: Device.Pins.D02,
                resetPin: Device.Pins.D01,
                width: 128, height: 127);


            //graphics.Clear();

            //graphics.Show();
            speccy = new ZXSpectrum(true, true, 32, 32, 0);
            speccy.Reset();
            graphics = new GraphicsLibrary(display);
            display.Clear(true);
            display.ClearScreen(1);
            display.InvertDisplay(false);
            graphics.DrawRectangle(0, 0, 127, 127, Color.FromHex("#00cdcd"), true);
            graphics.Show();
        }
Пример #20
0
        void TestILI9163()
        {
            Console.WriteLine("Clear display");

            // Drawing natively in the display
            display.ClearScreen(250);

            Console.WriteLine("Draw");

            for (int i = 0; i < 30; i++)
            {
                display.DrawPixel(i, i, true);
                display.DrawPixel(30 + i, i, true);
                display.DrawPixel(60 + i, i, true);
            }

            Console.WriteLine("Show");

            display.Show();

            Console.WriteLine("Show complete");

            // Drawing with Display Graphics Library
            graphics.CurrentFont = new Font8x8();
            graphics.Clear();
            graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red);
            graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false);
            graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false);
            graphics.DrawText(5, 5, "Meadow F7 SPI");
            graphics.Show();
        }
Пример #21
0
        static void UITest()
        {
            display.CurrentFont = new Font8x12();

            display.DrawText(4, 4, "abcdefghijklm", Color.SkyBlue);
            display.DrawText(4, 18, "nopqrstuvwxyz", Color.SkyBlue);
            display.DrawText(4, 32, "`1234567890-=", Color.SkyBlue);
            display.DrawText(4, 46, "~!@#$%^&*()_+", Color.SkyBlue);
            display.DrawText(4, 60, "[]\\;',./", Color.SkyBlue);
            display.DrawText(4, 74, "{}|:\"<>?", Color.SkyBlue);
            display.DrawText(4, 88, "ABCDEFGHIJKLM", Color.SkyBlue);
            display.DrawText(4, 102, "NOPQRSTUVWXYZ", Color.SkyBlue);

            display.CurrentFont = new Font4x8();
            display.DrawText(4, 116, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Color.White);
            display.DrawText(4, 126, "abcdefghijklmnopqrstuvwxyz", Color.White);
            display.DrawText(4, 136, "01234567890!@#$%^&*()_+-=", Color.White);
            display.DrawText(4, 146, "\\|;:'\",<.>/?[]{}", Color.White);
            display.Show();
            Thread.Sleep(20000);

            display.Clear();

            display.DrawLine(10, 10, 118, 150, Color.OrangeRed);
            display.Show();
            Thread.Sleep(500);
            display.DrawLine(118, 10, 10, 150, Color.OrangeRed);
            display.Show();
            Thread.Sleep(500);

            display.DrawCircle(64, 64, 25, Color.Purple);
            display.Show();
            Thread.Sleep(1000);

            display.DrawRectangle(5, 5, 118, 150, Color.Aquamarine);
            display.Show();
            Thread.Sleep(1000);

            display.DrawRectangle(10, 100, 108, 50, Color.Yellow, true);
            display.Show();
            Thread.Sleep(1000);

            var bytes = Resources.GetBytes(Resources.BinaryResources.trees);

            DrawBitmap(10, 120, bytes, tft);
            tft.Refresh();
        }
Пример #22
0
    void RotaryYClicked(object sender, EventArgs e)
    {
        x = y = 120;

        graphics.DrawRectangle(0, 0, 240, 240, Color.White, true);
        graphics.DrawPixel(x, y, Color.Red);
        graphics.Show();
    }
Пример #23
0
 protected void DisplayText(string text, int x = 12, int y = 12)
 {
     graphics.Clear();
     graphics.CurrentFont = font;
     graphics.DrawRectangle(0, 0, 128, 32);
     graphics.DrawText(x, y, text);
     graphics.Show();
 }
Пример #24
0
        public static void Main()
        {
            ePaper = new EPD2i7(chipSelectPin: Pins.GPIO_PIN_D4,
                                dcPin: Pins.GPIO_PIN_D7,
                                resetPin: Pins.GPIO_PIN_D6,
                                busyPin: Pins.GPIO_PIN_D5,
                                spiModule: SPI.SPI_module.SPI1,
                                speedKHz: 4000);

            /*     var e27 = (EPD2i7)ePaper;
             *
             *   e27.ClearFrame();
             *   e27.DisplayFrame();
             *   e27.Show();*/

            ePaper.Clear(false, true);

            display = new GraphicsLibrary(ePaper);

            display.DrawLine(10, 10, 94, 100);
            //   display.Show();
            //   Thread.Sleep(500);

            display.DrawCircle(52, 60, 32);
            //  display.Show();
            //   Thread.Sleep(500);

            display.DrawRectangle(5, 40, 60, 60);
            //  display.Show();
            //  Thread.Sleep(1000);

            display.DrawRectangle(20, 100, 40, 25, Color.Red, true);
            //   display.Show();
            //    Thread.Sleep(500);

            display.CurrentFont = new Font8x12();
            display.DrawText(2, 2, "Wilderness");
            display.CurrentFont = new Font8x8();
            display.DrawText(2, 16, "Netduino 3", Color.Red);

            display.Show();



            Thread.Sleep(-1);
        }
 void DisplayText(string text, int x = 12)
 {
     graphics.Clear();
     graphics.CurrentFont = new Font8x12();
     graphics.DrawRectangle(0, 0, 128, 32);
     graphics.DrawText(x, 12, text);
     graphics.Show();
 }
Пример #26
0
        void StartGameLoop()
        {
            while (true)
            {
                pongGame.Update();

                graphics.Clear();

                graphics.DrawCircle(pongGame.BallX, pongGame.BallY, pongGame.BallRadius, true, true);
                graphics.DrawRectangle(pongGame.PlayerX, pongGame.PlayerY, pongGame.PaddleWidth, pongGame.PaddleHeight, true, true);
                graphics.DrawRectangle(pongGame.CpuX, pongGame.CpuY, pongGame.PaddleWidth, pongGame.PaddleHeight, true, true);

                graphics.DrawText(52, 0, $"{pongGame.PlayerScore}:{pongGame.CpuScore}");

                graphics.Show();

                Thread.Sleep(10);
            }
        }
Пример #27
0
 // drawing helpers
 void FillWithColor(Color color)
 {
     // clear our buffer
     canvas.Clear();
     // draw a filled rectangle that fills the screen
     canvas.DrawRectangle(0, 0, dW, dH, color, filled: true);
     // copy the canvas contents to the device
     onboardLed.SetColor(color);
     canvas.Show();
 }
Пример #28
0
        public static void Main()
        {
            // I2C constructor
            // var oled = new SSD1306(Cpu.Pin.GPIO_Pin9, Cpu.Pin.GPIO_Pin10, Cpu.Pin.GPIO_Pin7, SPI.SPI_module.SPI1, 4000, SSD1306.DisplayType.OLED128x32);

            // SPI constructor
            var oled = new SSD1306(chipSelectPin: Pins.GPIO_PIN_D9,
                                   dcPin: Pins.GPIO_PIN_D10,
                                   resetPin: Pins.GPIO_PIN_D7,
                                   spiModule: SPI.SPI_module.SPI1,
                                   speedKHz: 400000,
                                   displayType: SSD1306.DisplayType.OLED128x32);

            oled.IgnoreOutOfBoundsPixels = true;

            var display = new GraphicsLibrary(oled);

            display.Clear(true);
            display.DrawLine(0, 0, 60, 28, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawCircle(63, 31, 20, true, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(20, 20, 60, 40);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.DrawRectangle(30, 10, 50, 40, true, true);
            display.Show();
            Thread.Sleep(1000);

            display.Clear(true);
            display.CurrentFont = new Font8x8();
            display.DrawText(4, 10, "NETDUINO 3 WiFi");
            display.Show();
            Thread.Sleep(Timeout.Infinite);
        }
Пример #29
0
        void JpegTest()
        {
            Console.WriteLine("Jpeg Test");

            var jpgData = LoadResource("meadow.jpg");

            Console.WriteLine($"Loaded {jpgData.Length} bytes, decoding jpeg ...");

            var decoder = new JpegDecoder();
            var jpg     = decoder.DecodeJpeg(jpgData);

            Console.WriteLine($"Jpeg decoded is {jpg.Length} bytes");
            Console.WriteLine($"Width {decoder.Width}");
            Console.WriteLine($"Height {decoder.Height}");

            graphics.Clear();
            graphics.DrawRectangle(0, 0, 240, 320, Color.White, true);

            int  x = 0;
            int  y = (320 - decoder.Height) / 2;
            byte r, g, b;

            for (int i = 0; i < jpg.Length; i += 3)
            {
                r = jpg[i];
                g = jpg[i + 1];
                b = jpg[i + 2];

                display.DrawPixel(x, y, r, g, b);

                x++;

                if (x % decoder.Width == 0)
                {
                    y++;
                    x = 0;
                }
            }

            Console.WriteLine("Jpeg show");

            display.Show();
        }
Пример #30
0
        /// <summary>
        /// Does the actual rendering. If it's already rendering, it'll bail out,
        /// so render requests don't stack up.
        /// </summary>
        protected void Render()
        {
            Console.WriteLine($"Render() - is rendering: {isRendering}");

            lock (renderLock) {   // if we're already rendering, bail out.
                if (isRendering)
                {
                    Console.WriteLine("Already in a rendering loop, bailing out.");
                    return;
                }

                isRendering = true;
            }

            graphics.Clear(true);

            graphics.Stroke = 1;
            graphics.DrawRectangle(0, 0, (int)display.Width, (int)display.Height, Color.White);
            graphics.DrawRectangle(5, 5, (int)display.Width - 10, (int)display.Height - 10, Color.White);

            graphics.DrawCircle((int)display.Width / 2, (int)display.Height / 2, (int)(display.Width / 2) - 10, Color.FromHex("#23abe3"), true);

            DisplayJPG();

            string text = $"{conditions.Temperature?.ToString("##.#")}°C";

            graphics.CurrentFont = new Font12x20();
            graphics.DrawText(
                x: (int)(display.Width - text.Length * 24) / 2,
                y: 140,
                text: text,
                color: Color.Black,
                scaleFactor: GraphicsLibrary.ScaleFactor.X2);

            graphics.Rotation = GraphicsLibrary.RotationType._270Degrees;

            graphics.Show();

            Console.WriteLine("Show complete");

            isRendering = false;
        }