-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadLDR.cpp
30 lines (26 loc) · 888 Bytes
/
readLDR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/** Simple LDR Reading Application
* Written by Derek Molloy for the book "Exploring BeagleBone: Tools and
* Techniques for Building with Embedded Linux" by John Wiley & Sons, 2014
* ISBN 9781118935125. Please see the file README.md in the repository root
* directory for copyright and GNU GPLv3 license information. */
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;
#define LDR_PATH "/sys/bus/iio/devices/iio:device0/in_voltage"
int readAnalog(int number){
stringstream ss;
ss << LDR_PATH << number << "_raw";
fstream fs;
fs.open(ss.str().c_str(), fstream::in);
fs >> number;
fs.close();
return number;
}
int main(int argc, char* argv[]){
cout << "Starting the readLDR program" << endl;
int value = readAnalog(0);
cout << "The LDR value was " << value << " out of 4095." << endl;
return 0;
}