MPC23S17
Readme-Version 1.0.12
This is a small library to communicate with a MCP23S17 io-expander.
Fixed
- fixed the chip.set( pin, value, true ) issue
What's working?
You can easily use this library to communicate with 16 of the MCP23S17 chips. You can read from and write to each of its 16 pins.
You should set the directions of each pin you are using. Connect every not used pin to GND and set as an input.
// 0 => Output Equivalent to the R/W bit// 1 => Inputs;
You can easily set any pin to hight or low with this code:
// s.set( pin, value );// this function will immediately publish the values to the chips;s; // s.set( pin, value, false );// this will NOT publish to the chips;// you have to manually publish to the chips;
To read one of the pins you can chose between this two functions:
// s.get( pin );// returns latest input of pin 0 (might be not the real one)s; s;
Is you want to read more than one pin with its real values, you can use this code:
s
You can also add callback functions to pins to detect changes.
// add a callback function to a single pin// this is NOT a hardware interrupt. The performance depends on how ofter you vall the read function// a hardware-implementation will may follows1;
Coming soon
- Support hardware-interrupts with callback functions
Example
v0.0.5
// load the libraryMCPLib = ; // create new instance width device and chip_adress// needed default settings are set (more options will follow)mcp_1 = '/dev/spidev0.0' ; s0 = mcp_1;s0; s1 = mcp_1;s1; // connect decivemcp_1; // add a callback function to a single pin// this is NOT a hardware interrupt. The performance depends on how ofter you vall the read function// a hardware-implementation will may follows1; var pin = 0;;