Madeline Kistler / sci_sensor
Committer:
mkistler
Date:
Mon Nov 09 17:32:44 2020 +0000
Revision:
1:ad071d4ef366
Child:
2:2a3d5370d769
Working library.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkistler 1:ad071d4ef366 1 #include "sci_sensor.h"
mkistler 1:ad071d4ef366 2
mkistler 1:ad071d4ef366 3 sci_sensor::sci_sensor(PinName in1, PinName in2): _in1(in1), _in2(in2)
mkistler 1:ad071d4ef366 4 {
mkistler 1:ad071d4ef366 5 c1 = -1481.96;
mkistler 1:ad071d4ef366 6 c2 = 2196200;
mkistler 1:ad071d4ef366 7 c3 = 1.8636;
mkistler 1:ad071d4ef366 8 c4 = 0.00000388;
mkistler 1:ad071d4ef366 9
mkistler 1:ad071d4ef366 10 la = -2;
mkistler 1:ad071d4ef366 11 lb = 3.8062;
mkistler 1:ad071d4ef366 12 }
mkistler 1:ad071d4ef366 13
mkistler 1:ad071d4ef366 14 //sci_sensor::LM20(PinName in2): _in2(in2)
mkistler 1:ad071d4ef366 15 //{
mkistler 1:ad071d4ef366 16
mkistler 1:ad071d4ef366 17 //}
mkistler 1:ad071d4ef366 18
mkistler 1:ad071d4ef366 19 float sci_sensor::temp()
mkistler 1:ad071d4ef366 20 {
mkistler 1:ad071d4ef366 21 float volt = _in1.read()*3.3;
mkistler 1:ad071d4ef366 22 float T = c1+sqrt(c2 + (c3-volt)/c4);
mkistler 1:ad071d4ef366 23 return T;
mkistler 1:ad071d4ef366 24
mkistler 1:ad071d4ef366 25 }
mkistler 1:ad071d4ef366 26
mkistler 1:ad071d4ef366 27 float sci_sensor::phc()
mkistler 1:ad071d4ef366 28 {
mkistler 1:ad071d4ef366 29 float volt = _in2.read()*3.3;
mkistler 1:ad071d4ef366 30 float res = (3.3*3300/volt - 3300)/1000.00; // 3300 is the resistance of my resistor
mkistler 1:ad071d4ef366 31 float lux = pow(10, la*log10(res)+lb); // A and B values were found using the graph for lux vs. resistance
mkistler 1:ad071d4ef366 32 return lux;
mkistler 1:ad071d4ef366 33 }