I don't have any errors but I really did not like the playground code for the light to frequency converter. I added in my own comments to the playground code because it was rather squirrely.
/*
* FILE: demo01.pde
* AUTHOR: Rob Tillaart
* DATE: 2011 05 16
Comments added by Jeremy Adair 9-13-12
*
* 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(9600);
Serial.println("START");
pinMode(10, INPUT);
digitalWrite(10, HIGH);
// this interrupt is based on hardware attached to the int0 pin
//each time the int0 pin sees a rising edge it will jump to
//the function irq1 and increase the count.
attachInterrupt(0, irq1, RISING);
}
///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{ // this code assumes one second has gone by in the if statement
// if other delays are in integrated code then this code will bomb
//because the one second interval is assumed in the loop.
//also, any time-critical serial communication will fail because
// the interrupt happens multiple times a second and needs to be turned off when not in use.
if (millis() - last > 1000)
{
last = millis();
t = cnt;
unsigned long hz = t - oldcnt; //the difference in counts
// per 1 assumed second = freq.
Serial.print("FREQ: ");
Serial.print(hz);
Serial.print("Hz \t = ");
Serial.print((hz+50)/100); // +50 == rounding last digit
Serial.println(" mW/m2");
oldcnt = t;
}
}
// END OF FILE
my points were made in the comments of the above playground code. Below are my alterations which give the exact same output but allow the code to be integrated.
/*
* FILE: alteredDemo from Rob Tillaart
* AUTHOR: Jeremy Adair
* DATE: 9-13-12
*
*
* 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 firstCnt;
unsigned long secondCnt;
void irq1()
{
cnt++;
}
///////////////////////////////////////////////////////////////////
//
// SETUP
//
void setup()
{
Serial.begin(9600);
Serial.println("START");
//pin 10 is for atmega1284p for INT0 (interrupt 0)
//double check your schematic for the INT0 for different boards.
pinMode(10, INPUT);
digitalWrite(10, HIGH);
}
///////////////////////////////////////////////////////////////////
//
// MAIN LOOP
//
void loop()
{
attachInterrupt(0, irq1, RISING);
firstCnt=cnt;
delay(1000);
secondCnt=cnt;
detachInterrupt(0);
unsigned long hz = secondCnt-firstCnt; // divide by 1 second
// is not shown
Serial.print("FREQ: ");
Serial.print(hz);
Serial.print("Hz \t = ");
Serial.print((hz+50)/100); // +50 == rounding last digit
Serial.println(" mW/m2");
}
// END OF FILE
Penny for your thoughts?