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

70 lines
1.1 KiB
Arduino
Raw Normal View History

2021-05-30 08:16:15 -04:00
//
// FILE: TSL235R_demo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// DATE: 2021-05-29
2021-12-29 07:37:09 -05:00
//
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-12-29 07:37:09 -05:00
//
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;
2021-12-29 07:37:09 -05:00
volatile uint32_t count = 0;
uint32_t oldCount = 0;
2021-05-30 08:16:15 -04:00
uint32_t t = 0;
uint32_t lastMeasurement = 0;
void count_irq()
{
2021-12-29 07:37:09 -05:00
count++;
2021-05-30 08:16:15 -04:00
}
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;
2021-12-29 07:37:09 -05:00
t = count;
uint32_t Hz = t - oldCount;
oldCount = t;
2021-05-30 08:16:15 -04:00
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");
}
}
2021-12-29 07:37:09 -05:00
2021-05-30 08:16:15 -04:00
// -- END OF FILE --
2021-12-29 07:37:09 -05:00