Código 2 TSL235

mail@pastecode.io avatar
unknown
c_cpp
3 years ago
974 B
4
Indexable
Never
#include <FreqCounter.h>

long irradiance;
long freq;
long  pulses;
const float area = 0.0092;
int cnt;
int pinLed=13;
short period = 100; // 100 ms Gate Time

void setup() {
  pinMode(pinLed, OUTPUT);
  Serial.begin(115200);        // connect to the serial port
  Serial.println("Frequency Counter");
}

void loop() {
 light();
 Serial.print(cnt++);
 Serial.print("  Pulses: ");
 Serial.print(pulses);
 Serial.print(";  Freq: ");
 Serial.print(freq);
 Serial.print(" Hz;  Irradiance: ");
 Serial.print(irradiance);
 Serial.println(" uW/cm2 = KHz");
 delay(1000);
}  

void light(){
  digitalWrite(pinLed, HIGH);
  FreqCounter::f_comp=10;   // Cal Value / Calibrate with professional Freq Counter
  FreqCounter::start(period);  // 100 ms Gate Time
  while (FreqCounter::f_ready == 0)
  pulses=FreqCounter::f_freq;
  delay(20);
  digitalWrite(pinLed, LOW);
  freq = (pulses*1000)/(period*area);
  irradiance = (freq/1000);
  return ;
}