/// <summary> /// Turn interrupts on or off and set the conversion trigger count. /// </summary> /// <remarks> /// The conversion count is the number of conversions that must be outside /// of the upper and lower limits before and interrupt is generated. /// See Interrupt Control Register on page 15 and 16 of the datasheet. /// </remarks> /// <param name="mode"></param> /// <param name="conversionCount"> /// Number of conversions that must be outside of the threshold before an interrupt is /// generated. /// </param> /// <param name="pin">GPIO pin connected to the TSL2561 interrupt pin. Set to null to use the previously supplied pin.</param> public void SetInterruptMode(InterruptMode mode, byte conversionCount, IDigitalPin pin = null) { if (conversionCount > 15) { throw new ArgumentOutOfRangeException("conversionCount", "Conversion count must be in the range 0-15 inclusive."); } // // Attach the interrupt event before we turn on interrupts. // if (pin != null) { if (_interruptPin != null) { //Port: TODO check _interruptPin.Dispose(); } _interruptPin = new DigitalInputPort(pin, false, ResistorMode.PullUp); _interruptPin.Changed += InterruptPin_Changed; } else { if (_interruptPin == null) { throw new ArgumentException("Interrupt pin must be supplied"); } } // // Put interrupt control in bits 4 & 5 of the Interrupt Control Register. // Using the enum above makes sure that mode is in the range 0-3 inclusive. // var registerValue = (byte)mode; registerValue <<= 4; // // conversionCount is known to be 0-15, put this in the lower four bits of // the Interrupt Control Register. // registerValue |= conversionCount; // // Clear the interrupt bit before we turn them on. // ClearInterrupt(); _tsl2561.WriteRegister(Registers.InterruptControl, registerValue); }
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); } }
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); } }
public IDigitalInputPort CreateDigitalInputPort( IPin pin, InterruptMode interruptMode = InterruptMode.None, ResistorMode resistorMode = ResistorMode.Disabled, double debounceDuration = 0, double glitchFilterCycleCount = 0) { if (IsValidPin(pin)) { if (resistorMode == ResistorMode.PullDown) { Console.WriteLine("Pull-down resistor mode is not supported."); throw new Exception("Pull-down resistor mode is not supported."); } var enablePullUp = resistorMode == ResistorMode.PullUp ? true : false; this.ConfigureInputPort(pin, enablePullUp, interruptMode); var port = new DigitalInputPort(this, pin, interruptMode); _inputPorts.Add(pin, port); return(port); } throw new Exception("Pin is out of range"); }
/// <summary> /// Configure the interrupts for the ADXL362. /// </summary> /// <remark> /// Set the interrupt mask for interrupt pins 1 and 2 /// pins to the interrupt pins on the ADXL362 if requested. /// /// Interrupts can be disabled by passing 0 for the interrupt maps. It is also /// possible to disconnect and ADXL362 by setting the interrupt pin /// to GPIO_NONE. /// </remark> /// <param name="interruptMap1">Bit mask for interrupt pin 1</param> /// <param name="interruptPin1">Pin connected to interrupt pin 1 on the ADXL362.</param> /// <param name="interruptMap2">Bit mask for interrupt pin 2</param> /// <param name="interruptPin2">Pin connected to interrupt pin 2 on the ADXL362.</param> public void ConfigureInterrupts(byte interruptMap1, IDigitalPin interruptPin1, byte interruptMap2 = 0, IDigitalPin interruptPin2 = null) // TODO: interrupPin2 = IDigitalPin.GPIO_NONE { _adxl362.WriteBytes(new byte[] { Command.WriteRegister, interruptMap1, interruptMap2 }); //TODO: I changed this from IDigitalPin.GPIO_NONE to null if (interruptPin1 != null) { _digitalInputPort1 = new DigitalInputPort(interruptPin1, false, MapResistorMode((interruptMap1 & 0xf0) > 0)); _digitalInputPort1.Changed += InterruptChanged; } else { _digitalInputPort1 = null; } //TODO: I changed this from IDigitalPin.GPIO_NONE to null if (interruptPin2 != null) { _digitalInputPort2 = new DigitalInputPort(interruptPin2, false, MapResistorMode((interruptMap2 & 0xf0) > 0)); _digitalInputPort2.Changed += InterruptChanged; } else { _digitalInputPort2 = null; } }