Exemple #1
0
        public void InitializeDigitalInputAndOutput()
        {
            if (_bcm2835.bcm2835_init() == 0)
            {
                throw new InvalidOperationException("bcm2835_init failed. Are you running as root?");
            }

            InitializeSpi();

            // Clear MCP23S17 GPIOs
            ClearDigitalOutputBits();

            ///*DIGITAL INPUT init decleration*/
            var Gpio_Arr_in = new[]
            {
                (byte)DigitalInput.Gpio_J14_16,
                (byte)DigitalInput.Gpio_J14_15,
                (byte)DigitalInput.Gpio_J14_14,
                (byte)DigitalInput.Gpio_J14_13,
                (byte)DigitalInput.Gpio_J15_12,
                (byte)DigitalInput.Gpio_J15_11,
                (byte)DigitalInput.Gpio_J15_10,
                (byte)DigitalInput.Gpio_J15_9,
                (byte)DigitalInput.Gpio_J16_8,
                (byte)DigitalInput.Gpio_J16_7,
                (byte)DigitalInput.Gpio_J16_6,
                (byte)DigitalInput.Gpio_J16_5,
                (byte)DigitalInput.Gpio_J17_4,
                (byte)DigitalInput.Gpio_J17_3,
                (byte)DigitalInput.Gpio_J17_2,
                (byte)DigitalInput.Gpio_J17_1,
            };

            for (var i = 0; i < Gpio_Arr_in.Length; ++i)
            {
                _bcm2835.bcm2835_gpio_fsel(Gpio_Arr_in[i], (byte)Bcm2835.bcm2835FunctionSelect.BCM2835_GPIO_FSEL_INPT);
                _bcm2835.bcm2835_gpio_set_pud(Gpio_Arr_in[i], (byte)Bcm2835.bcm2835PUDControl.BCM2835_GPIO_PUD_UP);
            }
        }
Exemple #2
0
        static int Main(string[] args)
        {
            // Will extract (from embedded resource) and compile the library
            // if it doesn't exist in the same directory as LibBcm2835.dll.
            Bcm2835.ExtractAndCompileLibraryIfNotExists();

            // Grabbing the instance will dynamically load the libbcm2835.so
            // library, so make sure it's there before accessing this property.
            Bcm2835 bcm2835 = Bcm2835.Instance;

            // If you call this, it will not actually access the GPIO
            // Use for testing
            // bcm2835.bcm2835_set_debug(1);

            if (bcm2835.bcm2835_init() == 0)
            {
                return(1);
            }

            // Set the pin to be an output
            bcm2835.bcm2835_gpio_fsel(pin, Bcm2835.HIGH);

            while (true)
            {
                // Turn it on
                bcm2835.bcm2835_gpio_write(pin, Bcm2835.HIGH);

                // wait a bit
                bcm2835.bcm2835_delay(500);

                // turn it off
                bcm2835.bcm2835_gpio_write(pin, Bcm2835.LOW);

                // wait a bit
                bcm2835.bcm2835_delay(500);
            }
            bcm2835.bcm2835_close();
            return(0);
        }