Skip to content

Instantly share code, notes, and snippets.

@virtuosonic
Created June 26, 2020 07:07
Show Gist options
  • Save virtuosonic/3dcebf516c7865ee9c05af0130b40192 to your computer and use it in GitHub Desktop.
Save virtuosonic/3dcebf516c7865ee9c05af0130b40192 to your computer and use it in GitHub Desktop.
#include <wiringPiSPI.h>
#include <iostream>
using namespace std;
int customAnalogRead(int spiPort)
{
unsigned char spiData[2];
spiData[0] = 0b11110000;
spiData[1] = 0;
wiringPiSPIDataRW(spiPort,spiData,2);
return ((spiData[0] << 7) | (spiData[1] >> 1)) & 0x3FF;
}
int main()
{
const auto port = 0;
wiringPiSPISetup (port, 1000000);
cout << customAnalogRead(port);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment