コード例 #1
0
        /// <summary>
        /// Set up the MCP23S17 for the PiFace Digital board
        /// </summary>
        private void InitPiFace()
        {
            InputPins = new PiFaceInputPin[8];
            for (int pinNo = 0; pinNo < 8; pinNo++)
            {
                InputPins[pinNo] = new PiFaceInputPin(pinNo);
            }

            OutputPins = new PiFaceOutputPin[8];
            for (int pinNo = 0; pinNo < 8; pinNo++)
            {
                OutputPins[pinNo] = new PiFaceOutputPin(pinNo);
            }

            if (spiConnection == null)
            {
                SpiConnectionSettings spiSettings = new SpiConnectionSettings {
                    BitsPerWord = 8, Delay = 1, MaxSpeed = 5000000, Mode = SpiMode.Mode0
                };
                spiConnection = new NativeSpiConnection(driverName, spiSettings);
            }

            Write(mcp23s17Register.IOCON, IOCON_SEQOP);
            SetAllOutputPins(0);

            // initialize output and input pins
            Write(mcp23s17Register.IODIRA, All_Pins_Output);
            Write(mcp23s17Register.IODIRB, All_Pins_Input);

            // set resistor on all input pins to pull up
            Write(mcp23s17Register.GPPUB, 0xFF);

            // set outputs
            UpdatePiFaceOutputPins();

            // Create re-usable buffer for polling input pins
            CreateReusableBufferForInputPolling();

            // Get the initial software input pin state and compare to actual inputs
            CachedInputState = PiFaceInputPin.AllPinState(InputPins);
            PollInputPins();
        }
コード例 #2
0
 /// <summary>
 /// Update PiFace board with the current vales of the software output pins
 /// </summary>
 public void UpdatePiFaceOutputPins()
 {
     Write(mcp23s17Register.GPIOA, PiFaceOutputPin.AllPinState(OutputPins));
 }