Madeline Kistler / sci_sensor
Committer:
mkistler
Date:
Mon Nov 09 17:44:05 2020 +0000
Revision:
2:2a3d5370d769
Parent:
1:ad071d4ef366
Commented.

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 2:2a3d5370d769 5 // Variables used the convert the temperature to celcius.
mkistler 1:ad071d4ef366 6 c1 = -1481.96;
mkistler 1:ad071d4ef366 7 c2 = 2196200;
mkistler 1:ad071d4ef366 8 c3 = 1.8636;
mkistler 1:ad071d4ef366 9 c4 = 0.00000388;
mkistler 1:ad071d4ef366 10
mkistler 2:2a3d5370d769 11 // Variables used to conver the photocell data to lux.
mkistler 1:ad071d4ef366 12 la = -2;
mkistler 1:ad071d4ef366 13 lb = 3.8062;
mkistler 1:ad071d4ef366 14 }
mkistler 1:ad071d4ef366 15
mkistler 2:2a3d5370d769 16 float sci_sensor::temp() // Function to return the temperature in celcius.
mkistler 1:ad071d4ef366 17 {
mkistler 2:2a3d5370d769 18 float volt = _in1.read()*3.3; // Converting the reading to voltage.
mkistler 2:2a3d5370d769 19 float T = c1+sqrt(c2 + (c3-volt)/c4); // Converting the voltage to celcius.
mkistler 2:2a3d5370d769 20 return T; // Returns the temperature in celcius.
mkistler 1:ad071d4ef366 21
mkistler 1:ad071d4ef366 22 }
mkistler 1:ad071d4ef366 23
mkistler 2:2a3d5370d769 24 float sci_sensor::phc() // Function to return the illuminensce in lux.
mkistler 1:ad071d4ef366 25 {
mkistler 2:2a3d5370d769 26 float volt = _in2.read()*3.3; // Converts raw data to voltage.
mkistler 2:2a3d5370d769 27 float res = (3.3*3300/volt - 3300)/1000.00; // 3300 is the resistance of my resistor. This function converts voltage to resistance of the photocell.
mkistler 2:2a3d5370d769 28 float lux = pow(10, la*log10(res)+lb); // Converts the resistance to lux.
mkistler 1:ad071d4ef366 29 return lux;
mkistler 1:ad071d4ef366 30 }