int readAnalog(int number){//这里就是读取电压的值:我们知道:AD转换的值是x/3.3*4095而成的。所以呢,我们的值最小是0,最大是4.95
stringstream ss;
ss << LDR_PATH << number << "_raw";//数据流方式来指定ADC的number
fstream fs;//文件流,在cpp中很方便
fs.open(ss.str().c_str(), fstream::in);//判断打开文件的路径和方式
fs >> number;//将读取到的值给number中
fs.close();
return number;
}
int main(int argc, char* argv[]){
cout << "Starting the readLDR program" << endl;
int value = readAnalog(0);//这里可知,我们使用的是ADC0
cout << "The LDR value was " << value << " out of 4095." << endl;
return 0;
}