Created
June 26, 2020 07:07
-
-
Save virtuosonic/3dcebf516c7865ee9c05af0130b40192 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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