示例#1
0
 public static void DrawCircleFractal(OLED _oledDisplay, int x, int y, int r)
 {
     _oledDisplay.DrawCircle(x, y, r, true);
     _oledDisplay.DrawCircle(x + r, y, r / 2, true);
     _oledDisplay.DrawCircle(x - r, y, r / 2, true);
     _oledDisplay.WriteDisplay();
 }
示例#2
0
        public void onDisplayUpdate(IntPtr buf, UInt16 w, UInt16 h)
        {
            //Debug.WriteLine("** Display Update ({0},{1})", w, h);

            // Marshal the screen buffer into a C# array
            int size = (int)(w * h * 2);

            byte[] screen = new byte[size];
            Marshal.Copy(buf, screen, 0, size);

            // Convert the screen buffer to a Bitmap
            Bitmap bmp = new Bitmap(w, h);
            int    x, y;
            int    i = 0;

            for (y = 0; y < h; y++)
            {
                for (x = 0; x < w; x++)
                {
                    // Convert 16-bit color (5:6:5) format to R,G,B
                    UInt16 color = (UInt16)((UInt16)screen[i] | (UInt16)screen[i + 1] << 8);
                    i += 2;

                    byte r = (byte)(((color & 0xF800) >> 11) * 255 / 31);
                    byte g = (byte)(((color & 0x07E0) >> 5) * 255 / 63);
                    byte b = (byte)((color & 0x001F) * 255 / 31);
                    bmp.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }

            // Draw the bitmap to the virtual OLED display
            OLED.Image = bmp;
            OLED.Invalidate();
        }
示例#3
0
        private static OLED InitializeOLED(Nusbio nusbio)
        {
            OLED oledDisplay = OLED_SSD1306.Create_128x64_09Inch_DirectlyIntoNusbio(nusbio);

            // Gpio7 is set to low to be the ground
            //oledDisplay = OLED_SH1106.Create_128x64_13Inch_DirectlyIntoNusbio(nusbio);
            oledDisplay.Debug = false;
            oledDisplay.Begin();
            return(oledDisplay);
        }
示例#4
0
        public static void CircleFractalDemo(OLED _oledDisplay, bool clearScreen)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Circle fractal demo");
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");
            var rnd  = new Random();
            var wait = 00;

            var sw = Stopwatch.StartNew();

            _oledDisplay.Clear(refresh: true);
            var r       = 16;
            var x       = _oledDisplay.Width / 2 - 1;
            var y       = _oledDisplay.Height / 2 - 1;
            var maxStep = 16;

            for (var i = 0; i < maxStep; i += r / 4)
            {
                if (clearScreen)
                {
                    _oledDisplay.Clear(false);
                }
                DrawCircleFractal(_oledDisplay, x + i, y - i, r);
                //oledDisplay.WriteDisplay();
            }
            for (var i = 0; i < maxStep; i += r / 4)
            {
                if (clearScreen)
                {
                    _oledDisplay.Clear(false);
                }
                DrawCircleFractal(_oledDisplay, x - i, y + i, r);
                //oledDisplay.WriteDisplay();
            }
            for (var i = 0; i < maxStep; i += r / 4)
            {
                if (clearScreen)
                {
                    _oledDisplay.Clear(false);
                }
                DrawCircleFractal(_oledDisplay, x + i, y + i, r);
                //oledDisplay.WriteDisplay();
            }
            for (var i = 0; i < maxStep; i += r / 4)
            {
                if (clearScreen)
                {
                    _oledDisplay.Clear(false);
                }
                DrawCircleFractal(_oledDisplay, x - i, y - i, r);
                //oledDisplay.WriteDisplay();
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
示例#5
0
        public static void TextDemo(OLED oledDisplay)
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, "Text demo");
            ConsoleEx.WriteMenu(-1, 4, "Q)uit");

            oledDisplay.DrawWindow(" NUSBIO ");

            var messages = new List <string>()
            {
                "Hello World",
                "Hello World.",
                "Hello World..",
                "Hello World...",
                "Written in C#",
                "or VB.net",
                "Could be done in F#",
                "PowerShell? Maybe!",
            };

            var messageIndex = 0;

            var goOn = true;

            while (goOn)
            {
                oledDisplay.WriteString(-1, 6 * 8, DateTime.Now.ToString());
                oledDisplay.WriteString(-1, 3 * 8, messages[messageIndex]);
                oledDisplay.WriteDisplay();
                oledDisplay.WriteString(-1, 3 * 8, messages[messageIndex], clearText: true);
                messageIndex++;
                if (messageIndex == messages.Count)
                {
                    messageIndex = 0;
                }

                ConsoleEx.WriteLine(0, 2, "Message Displayed:", ConsoleColor.Cyan);
                ConsoleEx.WriteLine(19, 2, messages[messageIndex].PadRight(64), ConsoleColor.Yellow);

                if (Console.KeyAvailable)
                {
                    var k = Console.ReadKey().Key;
                    if (k == ConsoleKey.Q)
                    {
                        goOn = false;
                    }
                }
                Thread.Sleep(900);
            }
            oledDisplay.Clear(refresh: true);
        }
        public static void Main()
        {
            //Using EEprom
            Boolean Connect_EEprom = true;

            //Using SS1306 OLED display
            Boolean Connect_OLED = false;

            if (Connect_EEprom)
            {
                EEprom24LC256 eeprom = new EEprom24LC256(EEprom24LC256.DeviceConnectionSting.I2C1, 0x54);

                String str = "This is an EEprom test for ESP32.";

                eeprom.Write(EEprom24LC256.Address.SecondString, str);

                str = eeprom.Read(EEprom24LC256.Address.SecondString);

                Console.WriteLine("\r\nReturned " + str);

                // If the string exist read it
                if (eeprom.Exist(EEprom24LC256.Address.ThirdString))
                {
                    str = eeprom.Read(EEprom24LC256.Address.ThirdString);

                    Console.WriteLine("\r\nReturned " + str);
                }

                else
                {
                    // String did not exist create it
                    string ts = "This is the thrid string we just created.";

                    eeprom.Write(EEprom24LC256.Address.ThirdString, ts);

                    ts = eeprom.Read(EEprom24LC256.Address.ThirdString);

                    Console.WriteLine("\r\nReturned " + str);
                }
            }

            if (Connect_OLED)
            {
                OLED oled = new OLED(OLED.DeviceConnectionSting.I2C1, 0x3C);

                oled.Initialize();

                oled.Write(0, 2, "Hello ESP32");

                oled.Write(0, 4, "Connected to I2C1");
            }
        }
示例#7
0
        public static void CircleDemo(OLED _oledDisplay)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Circle Demo");
            ConsoleEx.WriteMenu(0, 1, "Q)uit");
            var rnd = new Random();

            _oledDisplay.Clear(refresh: true);
            for (var i = 0; i < 16; i += 1)
            {
                var r = rnd.Next(2, 16);
                var x = rnd.Next(r + 1, _oledDisplay.Width - r);
                var y = rnd.Next(r + 1, _oledDisplay.Height - r);
                _oledDisplay.DrawCircle(x, y, r, true);
                _oledDisplay.WriteDisplay();

                Console.WriteLine("Circle {0:000},{1:000} r:{2:000}", x, y, r);
                TimePeriod.Sleep(125);
            }
        }
示例#8
0
        public static void RectangleDemo(OLED _oledDisplay, int wait)
        {
            Console.Clear();
            ConsoleEx.TitleBar(0, "Rectangle demo");
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            if (wait > 0)
            {
                _oledDisplay.DrawWindow("Rectangle Demo", "Slow Speed");
            }
            else
            {
                _oledDisplay.DrawWindow("Rectangle Demo", "Full Speed");
            }
            TimePeriod.Sleep(1000 * 2);

            var sw = Stopwatch.StartNew();

            for (var j = 1; j < 64; j++)
            {
                _oledDisplay.Clear(refresh: false);
                for (var i = 0; i < _oledDisplay.Height; i += j)
                {
                    _oledDisplay.DrawRect(i, i, _oledDisplay.Width - (i * 2), _oledDisplay.Height - (i * 2), true);
                    Console.WriteLine("Rectangle {0:000},{1:000} {2:000},{3:000}", i, i, _oledDisplay.Width - (i * 2), _oledDisplay.Height - (i * 2));
                }
                try {
                    // With Nusbio v 1.0A - FT232RL based this may throw
                    _oledDisplay.WriteDisplay();
                }
                catch { }
                if (wait > 0)
                {
                    TimePeriod.Sleep(wait);
                }
            }
            sw.Stop();
            _oledDisplay.DrawWindow("Rectangle demo", "The End.");
            Console.WriteLine("Execution Time:{0}. Hit space to continue", sw.ElapsedMilliseconds);
            var k = Console.ReadKey();
        }
示例#9
0
        public static void Main()
        {
            // Set i2c device configutation for the EEprom 24LC256 device
            I2CDevice.Configuration EEpromCon = I2cBus.AddNewDeviceConfiguration(0x54);

            // Set the shared I2CDevice.Configuration property
            EEprom24LC256.Initialize(EEpromCon);

            // Set i2c device configutation for the SS1306 OLED device
            I2CDevice.Configuration OLEDCon = I2cBus.AddNewDeviceConfiguration(0x3C);

            // Set the shared I2CDevice.Configuration property
            OLED.Initialize(OLEDCon);

            EEprom24LC256.Write(EEprom24LC256.Address.TestWrite, "Hello");

            OLED.Write(0, 0, "I2c Test", true);

            string ReturnString = string.Empty;

            if (EEprom24LC256.Exist(EEprom24LC256.Address.TestWrite))
            {
                ReturnString = EEprom24LC256.Read(EEprom24LC256.Address.TestWrite);

                Debug.Print("Exist " + ReturnString);
            }

            OLED.Write(0, 2, "First String: " + ReturnString, true);

            EEprom24LC256.Write(EEprom24LC256.Address.TestWrite, "World!");

            if (EEprom24LC256.Exist(EEprom24LC256.Address.TestWrite))
            {
                ReturnString = EEprom24LC256.Read(EEprom24LC256.Address.TestWrite);

                Debug.Print("The address exists " + ReturnString);
            }

            OLED.Write(0, 4, "Second String: " + ReturnString, true);
        }
示例#10
0
        public static void ExperimentDemo(OLED oledDisplay)
        {
            Console.Clear();

            ConsoleEx.TitleBar(0, "Text demo");
            ConsoleEx.WriteMenu(-1, 6, "Q)uit");

            //oledDisplay.Clear(refresh:true);
            //Thread.Sleep(1000);
            oledDisplay.Clear(true);
            for (var y = 0; y < 16; y += 1)
            {
                for (var x = 0; x < 128; x += 1)
                {
                    oledDisplay.SetPixel(x, y, true);
                    if (y > oledDisplay.Height - 24)
                    {
                        y = 0;
                    }
                }
                oledDisplay.WriteDisplay();
            }
        }
示例#11
0
        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;
            }
            // The PCF8574 has limited speed
            //Nusbio.BaudRate = 9600;

            using (var nusbio = new Nusbio(serialNumber))
            {
                Console.WriteLine("OLED Display Initialization");

                OLED oledDisplay = InitializeOLED(nusbio);
                oledDisplay.DrawWindow(" NUSBIO ", "Ready...");
                Cls(nusbio);

                while (nusbio.Loop())
                {
                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.I)
                        {
                            oledDisplay = InitializeOLED(nusbio);
                        }
                        if (k == ConsoleKey.Q)
                        {
                            oledDisplay.Clear(true);
                            nusbio.ExitLoop();
                        }
                        if (k == ConsoleKey.R)
                        {
                            RectangleDemo(oledDisplay, 80);
                            RectangleDemo(oledDisplay, 0);
                        }
                        if (k == ConsoleKey.P)
                        {
                            RectangleDemo(oledDisplay, 0);
                        }
                        if (k == ConsoleKey.T)
                        {
                            TextDemo(oledDisplay);
                        }
                        if (k == ConsoleKey.C)
                        {
                            CircleDemo(oledDisplay);
                        }
                        if (k == ConsoleKey.F)
                        {
                            CircleFractalDemo(oledDisplay, true);
                            CircleFractalDemo(oledDisplay, false);
                        }
                        if (k == ConsoleKey.H)
                        {
                            Cls(nusbio);
                            oledDisplay.Clear();
                        }
                        Cls(nusbio);
                        oledDisplay.DrawWindow(" NUSBIO ", "Ready...");
                    }
                }
            }
            Console.Clear();
        }