Beispiel #1
0
        public static void Main()
        {
            _mcp = new MCP23008(39);

            // create an array of ports
            DigitalOutputPort[] ports = new DigitalOutputPort[8];
            for (byte i = 0; i <= 7; i++)
            {
                ports[i] = _mcp.CreateOutputPort(i, false);
            }

            while (true)
            {
                // count from 0 to 7 (8 leds)
                for (int i = 0; i <= 7; i++)
                {
                    // turn on the LED that matches the count
                    for (byte j = 0; j <= 7; j++)
                    {
                        ports[j].State = (i == j);
                    }

                    Debug.Print("i: " + i.ToString());
                    Thread.Sleep(250);
                }
            }
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            //This example has not been fully tested yet. Turns out the lcd screen i have on hand was bad so until i have one to test with i cannot verify this is working.
            var deferral = taskInstance.GetDeferral();

            try
            {
                //create port expander IC and its proper pins for the screen
                MCP23008   register = new MCP23008(0x27, 26);
                List <Pin> allpins  = new List <Pin>();

                Pin rs = new Pin {
                    register = PinOpt.register.A, pin = PinOpt.pin.GP0, IO = PinOpt.IO.output
                };
                Pin e = new Pin {
                    register = PinOpt.register.A, pin = PinOpt.pin.GP1, IO = PinOpt.IO.output
                };
                Pin d4 = new Pin {
                    register = PinOpt.register.A, pin = PinOpt.pin.GP2, IO = PinOpt.IO.output
                };
                Pin d5 = new Pin {
                    register = PinOpt.register.A, pin = PinOpt.pin.GP3, IO = PinOpt.IO.output
                };
                Pin d6 = new Pin {
                    register = PinOpt.register.A, pin = PinOpt.pin.GP4, IO = PinOpt.IO.output
                };
                Pin d7 = new Pin {
                    register = PinOpt.register.A, pin = PinOpt.pin.GP5, IO = PinOpt.IO.output
                };

                allpins = new List <Pin> {
                    rs, e, d4, d5, d6, d7
                };
                register.addpins(allpins);
                register.init();

                //create the lcd screen object and provide it the expander and the pins
                HD44780U HD44780U;
                HD44780U = new HD44780U(register, 20, 2);
                await HD44780U.InitAsync(rs, e, d4, d5, d6, d7);

                await HD44780U.clearAsync();

                //write out to the lcd
                HD44780U.setCursor(0, 0);
                HD44780U.write("Windows 10 IoT");
                while (true)
                {
                    HD44780U.setCursor(0, 1);
                    HD44780U.write(DateTime.Now.ToString("hh:mm:ss:fff tt", System.Globalization.DateTimeFormatInfo.InvariantInfo));
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
Beispiel #3
0
        public Lcd2004(MCP23008 mcp)
        {
            DisplayConfig = new TextDisplayConfig {
                Height = 4, Width = 20
            };

            LCD_RS = mcp.CreateOutputPort(1, false);
            LCD_E  = mcp.CreateOutputPort(2, false);
            LCD_D4 = mcp.CreateOutputPort(3, false);
            LCD_D5 = mcp.CreateOutputPort(4, false);
            LCD_D6 = mcp.CreateOutputPort(5, false);
            LCD_D7 = mcp.CreateOutputPort(6, false);

            var lite = mcp.CreateOutputPort(7, true);

            Initialize();
        }
Beispiel #4
0
        public static void Main()
        {
            // Create a new MCP23008. This constructor shows how to pass
            // the address pin configuration instead of an address.
            _mcp = new MCP23008(false, false, false); // all address pins pulled low (address of 32)

            // Create a new DigitalInputPort from pin 0, pulled high
            DigitalInputPort port = _mcp.CreateInputPort(0, true);

            // loop forever
            while (true)
            {
                // Print the port value
                Debug.Print("Port value: " + (port.Value ? "high" : "low"));

                Thread.Sleep(250);
            }
        }
Beispiel #5
0
        public static void Main()
        {
            // Create a new MCP23008. This constructor shows how to pass
            // the address pin configuration instead of an address.
            _mcp = new MCP23008(true, true, true); // all address pins pulled high (address of 39)

            // Create a new DigitalInputPort from pin 0, pulled high
            DigitalInputPort port = _mcp.CreateInputPort(0, true);

            // wire up a changed handler to output to the console when the port changes.
            port.Changed += (object sender, PortInterruptEventArgs e) => {
                Debug.Print("Port changed event, value: " + ((e.ValueAtInterrupt) ? "high" : "low"));
            };

            // wait forever
            while (true)
            {
                Thread.Sleep(Timeout.Infinite);
            }
        }
Beispiel #6
0
        public static void Main()
        {
            // create a new MCP23008 with all address pins pulled low/GND (address of 32)
            _mcp = new MCP23008(false, false, false);

            // set pin 0 to input with pullup = true, interrupt = false
            _mcp.ConfigureInputPort(0, true, false);

            bool port0Value = false;

            // loop forever
            while (true)
            {
                // read the port 0's value
                port0Value = _mcp.ReadPort(0);
                Debug.Print("Port 0: " + ((port0Value) ? "high" : "low"));

                Thread.Sleep(250);
            }
        }
Beispiel #7
0
        public static void Main()
        {
            MCP23008 mcp = new MCP23008();

            ITextDisplay lcd = new Lcd2004(mcp);

            lcd.WriteLine("Wilderness Labs", 0);
            lcd.WriteLine(" Powering", 1);
            lcd.WriteLine("  Connected", 2);
            lcd.WriteLine("   Things", 3);

            //Thread.Sleep(3000);

            //lcd.Clear();

            //byte[] happyFace = { 0x0, 0x0, 0xa, 0x0, 0x11, 0xe, 0x0, 0x0 };
            //byte[] sadFace = { 0x0, 0x0, 0xa, 0x0, 0xe, 0x11, 0x0, 0x0 };
            //byte[] rocket = { 0x4, 0xa, 0xa, 0xa, 0x11, 0x15, 0xa, 0x0 };
            //byte[] heart = { 0x0, 0xa, 0x1f, 0x1f, 0xe, 0x4, 0x0, 0x0 };

            //// save the custom characters
            //lcd.SaveCustomCharacter(happyFace, 1);
            //lcd.SaveCustomCharacter(sadFace, 2);
            //lcd.SaveCustomCharacter(rocket, 3);
            //lcd.SaveCustomCharacter(heart, 4);

            //lcd.Clear();

            //// create our string, using the addresses of the characters
            //// casted to char.
            //StringBuilder s = new StringBuilder();
            //s.Append("1:" + (char)1 + " ");
            //s.Append("2:" + (char)2 + " ");
            //s.Append("3:" + (char)3 + " ");
            //s.Append("4:" + (char)4 + " ");
            //lcd.WriteLine(s.ToString(), 0);

            Thread.Sleep(Timeout.Infinite);
        }
Beispiel #8
0
        public static void Main()
        {
            _mcp = new MCP23008(39);

            while (true)
            {
                for (int i = 0; i <= 7; i++)
                {
                    // can write a byte mask that specifies all the pin
                    // values in one byte
                    _mcp.WriteToPorts((byte)(1 << i));

                    // or you can write to individual pins:
                    //for (int j = 0; j <= 7; j++) {
                    //    _mcp.WriteToPort(j, false);
                    //}
                    //_mcp.WriteToPort(i, true);

                    Debug.Print("i: " + i.ToString());
                    Thread.Sleep(250);
                }
            }
        }
Beispiel #9
0
        public static void Main()
        {
            // create our MCP23008
            MCP23008 mcp = new MCP23008(39); // all address pins pulled high

            // create a digital output port from that mcp
            DigitalOutputPort relayPort = mcp.CreateOutputPort(1, false);

            // create a new relay using that digital output port
            Relay relay = new Relay(relayPort);

            // loop forever
            while (true)
            {
                // toggle the relay
                relay.Toggle();

                Debug.Print("Relay on: " + relay.IsOn.ToString());

                // wait for 5 seconds
                Thread.Sleep(5000);
            }
        }
Beispiel #10
0
        public static void Run(string[] args)
        {
            Console.WriteLine("Nusbio Initializing");
            var serialNumber = Nusbio.Detect();

            if (serialNumber == null) // Detect the first Nusbio available
            {
                Console.WriteLine("Nusbio not detected");
                return;
            }

            var  clockPin        = NusbioGpio.Gpio0;
            var  dataOutPin      = NusbioGpio.Gpio1;
            byte MCP23008EP_ADDR = 0x20;

            using (var nusbio = new Nusbio(serialNumber))
            {
                // Add 8 new gpios named Gpio9 to Gpio16
                _mcp = new MCP23008(nusbio, dataOutPin, clockPin, gpioStartIndex: 9);
                _mcp.Begin(MCP23008EP_ADDR);

                _mcp.SetPinMode(NusbioGpioEx.Gpio9, PinMode.Output);
                _mcp.SetPinMode(NusbioGpioEx.Gpio10, PinMode.Output);
                _mcp.SetPinMode(NusbioGpioEx.Gpio11, PinMode.Output);
                _mcp.SetPinMode(NusbioGpioEx.Gpio12, PinMode.Output);
                _mcp.SetPinMode(NusbioGpioEx.Gpio13, PinMode.Output);
                _mcp.SetPinMode(NusbioGpioEx.Gpio14, PinMode.Input);
                _mcp.SetPinMode(NusbioGpioEx.Gpio15, PinMode.Input);
                _mcp.SetPinMode(NusbioGpioEx.Gpio16, PinMode.Input);

                Cls(nusbio);

                while (nusbio.Loop())
                {
                    _mcp.GPIOS[NusbioGpioEx.Gpio9].DigitalWrite(PinState.High);
                    _mcp.GPIOS[NusbioGpioEx.Gpio10].DigitalWrite(PinState.High);
                    TimePeriod.Sleep(200);

                    _mcp.GPIOS[NusbioGpioEx.Gpio9].DigitalWrite(PinState.Low);
                    _mcp.GPIOS[NusbioGpioEx.Gpio10].DigitalWrite(PinState.Low);
                    TimePeriod.Sleep(200);

                    ConsoleEx.Write(0, 4, string.Format("[{0}] Input14 detected:{1},{2} ", DateTime.Now,
                                                        _mcp.GPIOS[NusbioGpioEx.Gpio14].DigitalRead(),
                                                        _mcp.DigitalRead(14)
                                                        ), ConsoleColor.Cyan);

                    ConsoleEx.Write(0, 5, string.Format("[{0}] Input15 detected:{1},{2} ", DateTime.Now,
                                                        _mcp.GPIOS[NusbioGpioEx.Gpio15].DigitalRead(),
                                                        _mcp.DigitalRead(15)
                                                        ), ConsoleColor.Cyan);

                    ConsoleEx.Write(0, 6, string.Format("[{0}] Input16 detected:{1},{2} ", DateTime.Now,
                                                        _mcp.GPIOS[NusbioGpioEx.Gpio16].DigitalRead(),
                                                        _mcp.DigitalRead(16)
                                                        ), ConsoleColor.Cyan);

                    if (Console.KeyAvailable)
                    {
                        var k = Console.ReadKey(true).Key;
                        if (k == ConsoleKey.Q)
                        {
                            break;
                        }
                        if (k == ConsoleKey.C)
                        {
                            Cls(nusbio);
                        }
                    }
                }
            }
            Console.Clear();
        }
Beispiel #11
0
 protected void InitializePeripherals()
 {
     _mcp = new MCP23008(39);
 }