Help in understanding SPI interface on ofxGPIO

Hello! I’m planning a project using the Raspberry Pi and the MCP3008 ADC and I needed some help in understanding the example code available on the SPI interface of ofxGPIO.

void ofApp::update(){
         data[0] = 1;
         data[1] = 0b10000000 |( ((a2dChannel & 7) << 4));
         data[2] = 0;
         a2d.readWrite(data);//sizeof(data) );
         a2dVal = 0;
         a2dVal = (data[1]<< 8) & 0b1100000000;
         a2dVal |=  (data[2] & 0xff);
         cout << "The Result is: " << a2dVal << endl;
         usleep(5000);
}

I don’t exactly understand what’s happening here.

Also, if I plan to use all the inputs (8) on the chip, how do I do that?

1 Like

That particular ADC seems to be out of stock everywhere so I might have to go with an I2C interface instead, and a bit confused about that example code as well :frowning: