I'm trying to convert a square wave frequency to a voltage using PWM but when I compile I keep getting an error saying "In function 'void loop()':
error: redefinition of 'void loop()'" referring to the void loop() just after unsigned int tm_diff=0;
Here's the code I'm using:
#define TSL_FREQ_PIN 2 //output use digital pin2 for interrupt
int out = 3;unsigned long pulse_cnt=0;
void setup() {
//attach interrupt to pin2, sound output pin of TSL230R to arduino2
//call handler on each rising pulseattachInterrupt(0, add_pulse, RISING);
pinMode(TSL_FREQ_PIN, INPUT);
pinMode(out, OUTPUT);}
void loop() {
}
void add_pulse() {
//increase pulse count
pulse_cnt++;
return;
}//1000ms = 1s
#define READ_TM 1000;//two variable used to track time
unsigned long cur_tm=millis();
unsigned long pre_tm=cur_tm;//we'll need to access the amount of time passed
unsigned int tm_diff=0;
void loop() {
// check the value of the light sensor every READ_TM ms
// calculate how much time has passed
pre_tm = cur_tm;
cur_tm = millis();if( cur_tm > pre_tm ) {
tm_diff += cur_tm - pre_tm;
}
else if( cur_tm < pre_tm ) {
// handle overflow and rollover (Arduino 011)
tm_diff += ( cur_tm + ( 34359737 - pre_tm ));
}// if enough time has passed to do a new reading...
if( tm_diff >= READ_TM ) {
// re-set the ms counter
tm_diff = 0;// get our current frequency reading
unsigned long frequency = get_tsl_freq();}
}
unsigned long get_tsl_freq() {
// copy pulse counter and multiply.
// the multiplication is necessary for the current
// frequency scaling level. Please see the
// OUTPUT SCALING section below for more infounsigned long freq = pulse_cnt * 100;
// re-set pulse counter
pulse_cnt = 0;return(freq);
}
Any help would be great!