GY-63_MS5611/libraries/TSL235R/examples/TSL235R_demo/TSL235R_demo.ino

75 lines
1.2 KiB
Arduino
Raw Normal View History

2021-05-30 08:16:15 -04:00
//
// FILE: TSL235R_demo.ino
// AUTHOR: Rob Tillaart
2021-06-04 09:58:39 -04:00
// VERSION: 0.1.1
2021-05-30 08:16:15 -04:00
// PURPOSE: demo
// DATE: 2021-05-29
2021-06-04 09:58:39 -04:00
// NOTE
// This code will work up to ~150KHz on an Arduino UNO
// above that frequency the interrupt saturate the processor.
2021-05-30 08:16:15 -04:00
// Digital Pin layout ARDUINO
// =============================
// 2 IRQ 0 - to TSL235R
//
// PIN 1 - GND
// PIN 2 - VDD - 5V
// PIN 3 - SIGNAL
#include "TSL235R.h"
TSL235R mySensor;
volatile uint32_t cnt = 0;
uint32_t oldcnt = 0;
uint32_t t = 0;
uint32_t lastMeasurement = 0;
void count_irq()
{
cnt++;
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
2021-06-04 09:58:39 -04:00
pinMode(2, INPUT_PULLUP);
attachInterrupt(0, count_irq, FALLING);
2021-05-30 08:16:15 -04:00
mySensor.setWavelength(450);
}
void loop()
{
uint32_t now = millis();
if (now - lastMeasurement >= 1000)
{
lastMeasurement = now;
t = cnt;
uint32_t Hz = t - oldcnt;
oldcnt = t;
2021-06-04 09:58:39 -04:00
Serial.print("Hz: ");
Serial.print(Hz);
Serial.print("\t");
2021-05-30 08:16:15 -04:00
Serial.print(mySensor.irradiance(Hz)); // assumption 1 second
Serial.println(" uW/cm2");
}
}
// -- END OF FILE --