lauren cloutier / cloutier_a7_modular_programming
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PC20.cpp Source File

PC20.cpp

00001 //.cpp file for photocell, define coefficients and functions 
00002 
00003 #include "PC20.h" //include .h file to take variables/functions from class
00004 
00005 PC20::PC20 (PinName in2): _in2(in2) { //PC20 function in class PC20, define pin
00006     //initialize coefficients- corresponds to photocell data
00007     A= -2;
00008     B= 3.8;
00009     R= 10000;
00010     V= 3.3; 
00011 } //close PC20
00012 
00013 float PC20::photo(){ //PC20 photocell computation function (double column)
00014     float pc_volt= _in2.read()*3.3;//read volt from defined pin, *3.3 to get volt from %
00015     float R1=((R/pc_volt)-V)/1000; 
00016     float L= pow(10, A*log10(R1)+B);//lux formula with coefficients
00017     return L ; //returns value after function had been evaluated
00018     
00019 } //close float PC