BackgroundTaskDeferral _deferral;   // for a headless Windows 10 for IoT projects you need to hold a deferral to keep the app active in the background

        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();  // get the deferral handle

            MAX7219 driver = new MAX7219(4, MAX7219.Rotate.None, MAX7219.Transform.HorizontalFlip, MAX7219.ChipSelect.CE0);  // 4 panels, rotate 90 degrees, SPI CE0
            LED8x8Matrix matrix = new LED8x8Matrix(driver);     // pass the driver to the LED8x8Matrix Graphics Library

            while (true) {
                matrix.ScrollStringInFromRight("Hello World 2015 ", 100);
            }
        }
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();
            LED8x8Matrix matrix = new LED8x8Matrix(driver);

            BMP180 tempAndPressure = new BMP180();

            while (true)
            {
                var message = $"{Math.Round(tempAndPressure.Temperature.DegreesCelsius, 1)}C, {Math.Round(tempAndPressure.Pressure.Hectopascals, 1)}hPa ";

                matrix.ScrollStringInFromRight(message, 70);
            }
        }
예제 #3
0
        protected async void InitBanner()
        {
            matrix = new LED8x8Matrix(new Ht16K33());
            strip = new LED8x8Matrix(new MAX7219(4, MAX7219.Rotate.None, MAX7219.Transform.HorizontalFlip));

            matrix.SetBrightness(1);
            strip.SetBrightness(1);

            bmp180 = new BMP180(); // init temp and air pressure
            await InitLightAdc();  // init ldr on ads1015 adc


            ShowTempPressure();
            ShowLightLevel();

        }
        public void Initialise(string name, CloudMode cloudMode = CloudMode.None, bool initHat = false)
        {

            if (initHat)
            {
                Adc = new MCP3002();
                matrix = new LED8x8Matrix(new Ht16K33());
                bmp280TempPressure = new BMP280Sensor() { SampleRateMilliseconds = 30000 };

                InitialiseHat();
            }

            Util.SetName(name);
            SensorMgr.DeviceName = Util.GetHostName();

            StartNetworkServices(cloudMode);
        }
        private void ScrollText(string message, int repeatCount)
        {
            // update UI
            UpdateUi(message, repeatCount);

            //var driver = new Ht16K33(new byte[] { 0x70 }, Ht16K33.Rotate.None, LedDriver.Display.On, 2, LedDriver.BlinkRate.Off, "I2C1");
            var driver = new Ht16K33();

            LED8x8Matrix matrix = new LED8x8Matrix(driver);
            matrix.SetBrightness(1); // override default brightness

            // We'll repeat the message here
            for (int i = 0; i < repeatCount; i++)
            {
                matrix.FrameClear();
                matrix.ScrollStringInFromRight(message + "        ", 100);
                matrix.FrameClear();
            }
        }
        protected async void Initialise(string yourName = "Maker", CloudMode cloudMode = CloudMode.None)
        {
            Util.SetName(yourName);
            SensorMgr.DeviceName = Util.GetHostName();

            StartNetworkServices(cloudMode);

            InitialiseHatAsync(false, true, false).Wait();

            // for now not using the adc on the explorer hat as it's set to 3.3volts
            adcManager.Providers.Add(new ADS1015(Glovebox.IoT.Devices.Converters.ADS1015.Gain.Volt5));
            ADS1015 = (await adcManager.GetControllersAsync())[0];

            ShortLedShow();

            light = new LightSensor(ADS1015.OpenChannel((int)Pin.Analog.A3));
            temp = new TempSensor(ADS1015.OpenChannel((int)Pin.Analog.A4), 5000); //version one of wiring on Explorer Pro for ADC = 5v - this will change to 3.3v in the future 
            mem = new MemSensor();

            matrix = new LED8x8Matrix(new Ht16K33());
        }
        public async void Start() {

            var driver = new MAX7219(4, MAX7219.Rotate.None, MAX7219.Transform.HorizontalFlip, MAX7219.ChipSelect.CE1);

            LED8x8Matrix matrix = new LED8x8Matrix(driver);

            matrix.SetBrightness(2);

            while (true) {

                matrix.FrameClear();
                matrix.ScrollStringInFromRight("Hello World 2015", 100);

                matrix.FrameClear();
                matrix.ScrollStringInFromLeft("Hello World 2015", 100);

                //continue;

                for (ushort p = 0; p < matrix.PanelsPerFrame; p++) {
                    matrix.DrawSymbol(Grid8x8.Symbols.Block, Led.On, p);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }


                for (int p = 0; p < matrix.Length; p++) {
                    matrix.FrameSet(Led.On, p);
                    matrix.FrameSet(Led.On, matrix.Length - 1 - p);

                    matrix.FrameDraw();
                    await Task.Delay(2);

                    matrix.FrameSet(Led.Off, p);
                    matrix.FrameSet(Led.Off, matrix.Length - 1 - p);

                    matrix.FrameDraw();
                    await Task.Delay(2);
                }


                for (int c = 0; c < matrix.ColumnsPerFrame; c = c + 2) {
                    matrix.ColumnDrawLine(c);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }


                for (int r = 0; r < matrix.RowsPerPanel; r = r + 2) {
                    matrix.RowDrawLine(r);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                await Task.Delay(1000);

                for (ushort i = 0; i < matrix.PanelsPerFrame; i++) {
                    matrix.DrawLetter(i.ToString()[0], Led.On, i);
                }

                matrix.FrameDraw();
                await Task.Delay(1000);

                for (int r = 0; r < matrix.RowsPerPanel * 2; r++) {
                    matrix.FrameRollDown();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (int r = 0; r < matrix.RowsPerPanel * 2; r++) {
                    matrix.FrameRollUp();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (int c = 0; c < matrix.ColumnsPerFrame * 1; c++) {
                    matrix.FrameRollRight();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (int c = 0; c < matrix.ColumnsPerFrame * 1; c++) {
                    matrix.FrameRollLeft();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }


                //await Task.Delay(1000);
                //continue;

                matrix.DrawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890", 100, 0);
                matrix.FrameClear();

                for (int i = 0; i < matrix.RowsPerPanel; i++) {
                    matrix.DrawBox(i, i, matrix.ColumnsPerFrame - (i * 2), matrix.RowsPerPanel - (i * 2), Led.On);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (byte l = 0; l < 2; l++) {
                    matrix.SetFrameState(LedDriver.Display.Off);
                    await Task.Delay(250);
                    matrix.SetFrameState(LedDriver.Display.On);
                    await Task.Delay(250);
                }



                matrix.FrameClear();

                for (int r = 0; r < 2; r++) {
                    for (int i = 0; i < matrix.RowsPerPanel; i++) {
                        matrix.RowDrawLine(i, i - 0, matrix.ColumnsPerFrame - i - 1);
                        matrix.FrameDraw();
                        await Task.Delay(50);
                    }

                    //for (byte l = 0; l < 6; l++) {
                    //    matrix.SetBrightness(l);
                    //    await Task.Delay(250);
                    //}

                    //matrix.SetBrightness(1);

                    for (int i = 0; i < matrix.RowsPerPanel; i++) {
                        matrix.RowDrawLine(i, i - 0, matrix.ColumnsPerFrame - i - 1, Led.Off);
                        matrix.FrameDraw();
                        await Task.Delay(50);
                    }
                }

                await Task.Delay(500);
                matrix.FrameClear();

                matrix.ScrollStringInFromRight("Hello World ", 100);
                matrix.FrameClear();
                matrix.ScrollStringInFromLeft("Happy Birthday ", 100);


                for (int i = 0; i < matrix.fontSimple.Length; i = i + matrix.PanelsPerFrame) {
                    for (int p = 0; p < matrix.PanelsPerFrame; p++) {
                        if (p + i >= matrix.fontSimple.Length) { break; }
                        matrix.DrawBitmap(matrix.fontSimple[p + i], Led.On, (p + i) % matrix.PanelsPerFrame);
                    }
                    matrix.FrameDraw();
                    await Task.Delay(100 * matrix.PanelsPerFrame);
                }

                foreach (Grid8x8.Symbols sym in Enum.GetValues(typeof(Grid8x8.Symbols))) {
                    for (int p = 0; p < matrix.PanelsPerFrame; p++) {
                        matrix.DrawSymbol(sym, Led.On, p);
                    }
                    matrix.FrameDraw();
                    await Task.Delay(100 * matrix.PanelsPerFrame);
                }
            }
        }
        public async void Start() {

            Pixel[] palette = new Pixel[] { BiColour.Red, BiColour.Green, BiColour.Yellow };


            var driver = new Ht16K33BiColor(new byte[] { 0x71 }, Ht16K33BiColor.Rotate.D90);
            LED8x8Matrix matrix = new LED8x8Matrix(driver);

            matrix.SetBrightness(6);

            while (true) {

                matrix.FrameClear();
                matrix.ScrollStringInFromRight("Hello World 2015", 60, new Pixel[] { BiColour.Red, BiColour.Green, BiColour.Yellow });

                matrix.FrameClear();
                matrix.ScrollStringInFromLeft("Hello World 2015", 100, palette);

                //continue;

                for (ushort p = 0; p < matrix.PanelsPerFrame; p++) {
                    matrix.DrawSymbol(Grid8x8.Symbols.Block, BiColour.Red, p);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }


                for (int p = 0; p < matrix.Length; p++) {
                    matrix.FrameSet(BiColour.Green, p);
                    matrix.FrameSet(BiColour.Green, matrix.Length - 1 - p);

                    matrix.FrameDraw();
                    await Task.Delay(2);

                    matrix.FrameSet(Led.Off, p);
                    matrix.FrameSet(Led.Off, matrix.Length - 1 - p);

                    matrix.FrameDraw();
                    await Task.Delay(2);
                }


                for (int c = 0; c < matrix.ColumnsPerFrame; c = c + 2) {
                    matrix.ColumnDrawLine(c);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }


                for (int r = 0; r < matrix.RowsPerPanel; r = r + 2) {
                    matrix.RowDrawLine(r, BiColour.Yellow);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                await Task.Delay(1000);

                for (ushort i = 0; i < matrix.PanelsPerFrame; i++) {
                    matrix.DrawLetter(i.ToString()[0], BiColour.Green, i);
                }

                matrix.FrameDraw();
                await Task.Delay(1000);

                for (int r = 0; r < matrix.RowsPerPanel * 2; r++) {
                    matrix.FrameRollDown();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (int r = 0; r < matrix.RowsPerPanel * 2; r++) {
                    matrix.FrameRollUp();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (int c = 0; c < matrix.ColumnsPerFrame * 1; c++) {
                    matrix.FrameRollRight();
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (int c = 0; c < matrix.ColumnsPerFrame * 1; c++) {
                    matrix.FrameRollLeft();
                    matrix.FrameDraw();
                    await Task.Delay(50);
                }

                matrix.DrawString("Wow, such colour :)", palette, 200, 0);
                matrix.FrameClear();

                for (int i = 0; i < matrix.RowsPerPanel; i++) {
                    matrix.DrawBox(i, i, matrix.ColumnsPerFrame - (i * 2), matrix.RowsPerPanel - (i * 2), Led.On);
                    matrix.FrameDraw();
                    await Task.Delay(100);
                }

                for (byte l = 0; l < 2; l++) {
                    matrix.SetFrameState(LedDriver.Display.Off);
                    await Task.Delay(250);
                    matrix.SetFrameState(LedDriver.Display.On);
                    await Task.Delay(250);
                }



                matrix.FrameClear();

                for (int r = 0; r < 4; r++) {
                    for (int i = 0; i < matrix.RowsPerPanel; i++) {
                        matrix.RowDrawLine(i, i - 0, matrix.ColumnsPerFrame - i - 1, palette[i % palette.Length]);
                        matrix.FrameDraw();
                        await Task.Delay(50);
                    }


                    for (int i = 0; i < matrix.RowsPerPanel; i++) {
                        matrix.RowDrawLine(i, i - 0, matrix.ColumnsPerFrame - i - 1, Led.Off);
                        matrix.FrameDraw();
                        await Task.Delay(50);
                    }
                }

                await Task.Delay(250);
                matrix.FrameClear();


                for (int i = 0; i < matrix.fontSimple.Length; i = i + matrix.PanelsPerFrame) {
                    for (int p = 0; p < matrix.PanelsPerFrame; p++) {
                        if (p + i >= matrix.fontSimple.Length) { break; }
                        matrix.DrawBitmap(matrix.fontSimple[p + i], palette[i % palette.Length], (p + i) % matrix.PanelsPerFrame);
                    }
                    matrix.FrameDraw();
                    await Task.Delay(150 * matrix.PanelsPerFrame);
                }

                foreach (Grid8x8.Symbols sym in Enum.GetValues(typeof(Grid8x8.Symbols))) {
                    for (int p = 0; p < matrix.PanelsPerFrame; p++) {
                        matrix.DrawSymbol(sym, palette[p % palette.Length], p);
                    }
                    matrix.FrameDraw();
                    await Task.Delay(150 * matrix.PanelsPerFrame);
                }
            }
        }
        public MainPage()
        {
            this.InitializeComponent();



            var driver = new Ht16K33(new byte[] { 0x70 }, Ht16K33.Rotate.None, LedDriver.Display.On, 2, LedDriver.BlinkRate.Off, "I2C1");

            LED8x8Matrix matrix = new LED8x8Matrix(driver);

            matrix.SetBrightness(1);

            while (true)
            {

                matrix.FrameClear();

                for (int i = 0; i < matrix.fontSimple.Length; i = i + matrix.PanelsPerFrame)
                {
                    for (int p = 0; p < matrix.PanelsPerFrame; p++)
                    {
                        if (p + i >= matrix.fontSimple.Length) { break; }
                        matrix.DrawBitmap(matrix.fontSimple[p + i], Led.On, (p + i) % matrix.PanelsPerFrame);
                    }
                    matrix.FrameDraw();
                    Task.Delay(100 * matrix.PanelsPerFrame);
                }

                foreach (Grid8x8.Symbols sym in Enum.GetValues(typeof(Grid8x8.Symbols)))
                {
                    for (int p = 0; p < matrix.PanelsPerFrame; p++)
                    {
                        matrix.DrawSymbol(sym, p);
                    }
                    matrix.FrameDraw();
                    Task.Delay(100 * matrix.PanelsPerFrame);
                }

                matrix.FrameClear();
                matrix.ScrollStringInFromRight("Hello World 2016", 100);

                matrix.FrameClear();
                matrix.ScrollStringInFromLeft("Hello World 2016", 100);

                //continue;

                for (ushort p = 0; p < matrix.PanelsPerFrame; p++)
                {
                    matrix.DrawSymbol(Grid8x8.Symbols.Block, p);
                    matrix.FrameDraw();
                    Task.Delay(100);
                }


                for (int p = 0; p < matrix.Length; p++)
                {
                    matrix.FrameSet(Led.On, p);
                    matrix.FrameSet(Led.On, matrix.Length - 1 - p);

                    matrix.FrameDraw();
                    Task.Delay(2);

                    matrix.FrameSet(Led.Off, p);
                    matrix.FrameSet(Led.Off, matrix.Length - 1 - p);

                    matrix.FrameDraw();
                    Task.Delay(2);
                }


                for (int c = 0; c < matrix.ColumnsPerFrame; c = c + 2)
                {
                    matrix.ColumnDrawLine(c);
                    matrix.FrameDraw();
                    Task.Delay(100);
                }


                for (int r = 0; r < matrix.RowsPerPanel; r = r + 2)
                {
                    matrix.RowDrawLine(r);
                    matrix.FrameDraw();
                    Task.Delay(100);
                }

                Task.Delay(1000);

                for (ushort i = 0; i < matrix.PanelsPerFrame; i++)
                {
                    matrix.DrawLetter(i.ToString()[0], i);
                }

                matrix.FrameDraw();
                Task.Delay(1000);

                for (int r = 0; r < matrix.RowsPerPanel * 2; r++)
                {
                    matrix.FrameRollDown();
                    matrix.FrameDraw();
                    Task.Delay(100);
                }

                for (int r = 0; r < matrix.RowsPerPanel * 2; r++)
                {
                    matrix.FrameRollUp();
                    matrix.FrameDraw();
                    Task.Delay(100);
                }

                for (int c = 0; c < matrix.ColumnsPerFrame * 1; c++)
                {
                    matrix.FrameRollRight();
                    matrix.FrameDraw();
                    Task.Delay(100);
                }

                for (int c = 0; c < matrix.ColumnsPerFrame * 1; c++)
                {
                    matrix.FrameRollLeft();
                    matrix.FrameDraw();
                    Task.Delay(100);
                }


                //await Task.Delay(1000);
                //continue;

                matrix.DrawString("ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890", 100, 0);
                matrix.FrameClear();

                for (int i = 0; i < matrix.RowsPerPanel; i++)
                {
                    matrix.DrawBox(i, i, matrix.ColumnsPerFrame - (i * 2), matrix.RowsPerPanel - (i * 2));
                    matrix.FrameDraw();
                    Task.Delay(100);
                }

                for (byte l = 0; l < 2; l++)
                {
                    matrix.SetFrameState(LedDriver.Display.Off);
                    Task.Delay(250);
                    matrix.SetFrameState(LedDriver.Display.On);
                    Task.Delay(250);
                }



                matrix.FrameClear();

                for (int r = 0; r < 2; r++)
                {
                    for (int i = 0; i < matrix.RowsPerPanel; i++)
                    {
                        matrix.RowDrawLine(i, i - 0, matrix.ColumnsPerFrame - i - 1);
                        matrix.FrameDraw();
                        Task.Delay(50);
                    }

                    //for (byte l = 0; l < 6; l++) {
                    //    matrix.SetBrightness(l);
                    //    await Task.Delay(250);
                    //}

                    //matrix.SetBrightness(1);

                    for (int i = 0; i < matrix.RowsPerPanel; i++)
                    {
                        matrix.RowDrawLine(i, i - 0, matrix.ColumnsPerFrame - i - 1, Led.Off);
                        matrix.FrameDraw();
                        Task.Delay(50);
                    }
                }

                Task.Delay(500);
                matrix.FrameClear();

                matrix.ScrollStringInFromRight("Hello World ", 100);
                matrix.FrameClear();
                matrix.ScrollStringInFromLeft("Happy Birthday ", 100);


                }
            }