Hi,
I need help with this code, originally contributed by Rob Tilllaart, to add a second TSL235 light sensor. There is no need or a datasheet for the sensor - the TSL235 is just a square wave source. In the program, digital pin 2 is counting rising edges of a square wave signal input for one second, with attachInterrupt, then printing the counts as Hz. The second TSL235 will use digital pin 3 the same way. The goal is to have the outputs from both sensors read to serial output. Any help much appreciated.
Thanks, David
/*
* FILE: demo01.pde
* AUTHOR: Rob Tillaart
* DATE: 2011 05 16
*
* PURPOSE: prototype TSL235R monitoring
*
* Digital Pin layout ARDUINO
* =============================
* 2 IRQ 0 - to TSL235R
*
* PIN 1 - GND
* PIN 2 - VDD - 5V
* PIN 3 - SIGNAL
*
*/
volatile unsigned long cnt = 0;
unsigned long oldcnt = 0;
unsigned long t = 0;
unsigned long last;
void irq1()
{
cnt++;
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(115200);
Serial.println("START");
pinMode(2, INPUT);
digitalWrite(2, HIGH);
attachInterrupt(0, irq1, RISING);
}
///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{
if (millis() - last > 1000)
{
last = millis();
t = cnt;
unsigned long hz = t - oldcnt;
Serial.print("FREQ: ");
Serial.print(hz);
Serial.print("\t = ");
Serial.print((hz+50)/100); // +50 == rounding last digit
Serial.println(" mW/m2");
oldcnt = t;
}
}
// END OF FILE