Exemplo n.º 1
0
        public void InitGpio()
        {
            try
            {
                gpioController = GpioController.Instance;

                //Set Direction of pins (Input or Output)

                pin17 = gpioController.OpenPin(17);
                pin17.SetDriveMode(GpioPinDriveMode.Input);

                pin22 = gpioController.OpenPin(22);
                pin22.SetDriveMode(GpioPinDriveMode.Input);

                //Init value
                dt1            = DateTime.Now;
                stateChange    = 0;
                oldStatusPin17 = "";

                DeviceReady = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Init Gpio Error : " + ex.Message);
                DeviceReady = false;
            }
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="pin"></param>
        /// <param name="mode">The drive mode of the pin. When inputPullUp is used, the pressed state will be true when a falling edge is detected.</param>
        public Button(IGpioPin pin, GpioPinDriveMode mode)
        {
            if (pin == null) throw new ArgumentNullException("pin");
            if (mode != GpioPinDriveMode.Input && mode != GpioPinDriveMode.InputPullDown && mode != GpioPinDriveMode.InputPullUp) throw new ArgumentOutOfRangeException("mode", "Drive mode should be an input drive type.");

            _pin = pin;
            _pressedEdge = mode == GpioPinDriveMode.InputPullUp ? GpioPinEdge.FallingEdge : GpioPinEdge.RisingEdge;
            _pin.SetDriveMode(mode);
            _pin.ValueChanged += _pin_ValueChanged;
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="enablePin">Enablepin, a soft pwm driver will be connected to the pin.</param>
        /// <param name="in1Pin">In1 pin.</param>
        /// <param name="in2Pin">In2 pin.</param>
        public L293d(int enablePin, int in1Pin, int in2Pin)
        {
            _enablePin = new SoftPwmDriver(enablePin);
            _in1Pin = GenericGpioController.GetDefault().OpenPin(in1Pin);
            _in1Pin.SetDriveMode(GpioPinDriveMode.Output);
            _in2Pin = GenericGpioController.GetDefault().OpenPin(in2Pin);
            _in2Pin.SetDriveMode(GpioPinDriveMode.Output);

            _in1Pin.Write(GpioPinValue.Low);
            _in2Pin.Write(GpioPinValue.Low);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="trigPin">pin number of the trig of the sensor.</param>
        /// <param name="echoPin">pint number of the echo of the sensor.</param>
        public UltraSonicSensor(int trigPin, int echoPin)
        {
            _trigPin = GenericGpioController.GetDefault().OpenPin(trigPin);
            _trigPin.SetDriveMode(GpioPinDriveMode.Output);

            _echoPin = GenericGpioController.GetDefault().OpenPin(echoPin);
            _echoPin.SetDriveMode(GpioPinDriveMode.Input);

            _trigPin.Write(GpioPinValue.Low);

            _echoPin.ValueChanged += _echoPin_ValueChanged;
            _timer = new Stopwatch();
        }
Exemplo n.º 5
0
        private MCP23008GpioController(I2cDevice i2cDevice, IGpioPin interruptPin = null)
        {
            _i2cDevice    = i2cDevice;
            _interruptPin = interruptPin;

            if (_interruptPin != null)
            {
                _interruptPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
                _interruptPin.DebounceTimeout = TimeSpan.FromTicks(0);
                _interruptPin.ValueChanged   += InterruptPin_ValueChanged;
            }

            this._gpioPin = new MCP23008GpioPin[PinCount];
        }
        private MCP23017GpioController(I2cDevice i2cDevice, IGpioPin interruptPinA = null, IGpioPin interruptPinB = null)
        {
            _i2cDevice     = i2cDevice;
            _interruptPinA = interruptPinA;

            if (_interruptPinA != null)
            {
                _interruptPinA.SetDriveMode(GpioPinDriveMode.InputPullUp);
                _interruptPinA.DebounceTimeout = TimeSpan.FromTicks(0);
                _interruptPinA.ValueChanged   += InterruptPinA_ValueChanged;
            }

            _interruptPinB = interruptPinB;

            if (_interruptPinB != null)
            {
                _interruptPinB.SetDriveMode(GpioPinDriveMode.InputPullUp);
                _interruptPinB.DebounceTimeout = TimeSpan.FromTicks(0);
                _interruptPinB.ValueChanged   += InterruptPinB_ValueChanged;
            }

            this._gpioPin = new MCP23017GpioPin[PinCount];
        }
Exemplo n.º 7
0
Arquivo: Led.cs Projeto: shrekjxf/Rpi
 public Led(IGpioController controller, GpioEnum gpio, bool initialValue = false)
 {
     Pin = controller.OpenPin(gpio);
     Pin.Write(initialValue ? GpioPinValueEnum.Low : GpioPinValueEnum.High);
     Pin.SetDriveMode(GpioPinDriveModeEnum.Output);
 }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="pin">Pin the led is connected on.</param>
 public Led(int pin)
 {
     _pin = GenericGpioController.GetDefault().OpenPin(pin);
     _pin.SetDriveMode(GpioPinDriveMode.Output);
 }