CS (chip select) pin, can be any digital pin, to allow multiple devices.
Pot2boolean
DECpulse
Decrement Step
DONEpulse
To use the node in your project you should have the xodballxod/digipot-mcp-spi library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
// used for MicroChip Technology MCP413X/415X/423X/425X SPI controlled digitial potentiometers and rheostats
// Reference for Wiring: http://www.learningaboutelectronics.com/Articles/MCP4131-digital-potentiometer-circuit.php
#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_DEC
#pragma XOD error_raise enable
node {
void evaluate(Context ctx) {
if (!isInputDirty<input_DEC>(ctx))
return;
static_assert(isValidDigitalPort(constant_input_CS), "must be a valid digital port");
::pinMode(constant_input_CS, OUTPUT); // set pinmode output for Chip Select
auto digipot = getValue<input_SPI>(ctx);
uint8_t address = (uint8_t) getValue<input_Pot2>(ctx) ? _BV(4) : 0x00 ;
uint8_t command = (uint8_t) 0b1000 ; // Decrement
::digitalWrite(constant_input_CS, false); // chip select active
digipot->transfer( address | command ); // value
::digitalWrite(constant_input_CS, true); // chip select unactive
emitValue<output_DONE>(ctx, 1);
}
}