Writing to MCPXXXXChip

I’m working on a sketch that reads a joystick pad on my ipad and sends x/y values to a MCP4261 chip. I’m using Arduino Manager as the IOS app and Arduino Code Manager was used to create the starting sketch.

I have modified the sketch to determine the 2 pieces of data to send to the chip - the address (0 or 18) and a value between 0 and 255, which is the pospot variable. I will be using pin 4 on my Uno to send this data.

I think I need to use commands digitWrite and SPI.transfer but I’m unsure if these are the right commands and where to ‘put’ them.

I’ve attached the sketch

BTW - I know there are extra code in the sketch which I’ll be deleting

Thanks

Proto2.ino (2.07 KB)

Read about the SPI library in the Arduino reference.

Connect the chip like this: SCK -> Arduino SCLK DO -> Arduino MISO DI -> Arduino MOSI CS -> Arduino data pin, typically SS (10 on the UNO)

To write:

digitalWrite(10, LOW);
SPI.transfer(data1);  // first byte
SPI.transfer(data2);  // second byte
... 
digitalWrite(10, HIGH);

I understand that, what I'm unsure is where to put it in my sketch. Also I have two SPI devices, an Adafruit BLE and the MCP4261. I'm using Pin 10 for the BLE and Pin 4 for the MCP4261

Thanks