teckel: New version of the Timer FreeTone library released.
This release was actually tested on an Arduino, so I'm sure it works now. I also fixed/changed a few things. It generates code that's a bit smaller as well. Let me know how it works for you!
Tim
evancleary: hi Tim,
thanks for the library, I am trying to play a tone before a for loop but when i place it there in the code the tone repeats and the code freezes
any ideas?
#include
#include
SevenSeg disp1(30,31,32,33,34,35,36); SevenSeg disp2(40,41,42,43,44,45,46);
const int numOfDigits1 = 3; const int numOfDigits2 = 2; int digitPins1[numOfDigits1] = {2,3,4}; int digitPins2[numOfDigits2] = {5,6};
void setup() { disp1.setDigitPins(numOfDigits1,digitPins1); disp1.setDigitDelay(2000); disp1.setTimer(1); disp1.startTimer();
disp2.setDigitPins(numOfDigits2,digitPins2); disp2.setDigitDelay(2000); disp2.setTimer(2); disp2.startTimer(); disp1.setCommonCathode(); disp2.setCommonCathode();
}
void loop() { disp2.write(23); TimerFreeTone(13, 500, 500); for (int i = 180; i >= 0; i--){ disp1.writeClock(i); delay(100); }
}
ISR(TIMER1_COMPA_vect){ disp1.interruptAction(); }
ISR(TIMER2_COMPA_vect){ disp2.interruptAction(); }
So, you're saying if you comment out JUST this line: TimerFreeTone(13, 500, 500); it hangs? Could it be that it's always hanging but you don't realize it? In other words, the audio indicator is telling you it's hanging, but it's also hanging without TimerFreeTone you just can't tell because there's no audio indication?
TimerFreeTone doesn't use timer interrupts. But, it does use delayMicroseconds. If SevenSeg.h messes with the Arduino timer in such a way that it messes up delayMicroseconds, it could cause a problem.
Have you tried contacting the SevenSeg.h authors? TimerFreeTone is very simple, the entire code is here to review:
It does nothing fancy, sets the pin to output mode, calculates the square wave duration (frequency) and note duration (loops) and runs a "for" statement for however many loops are required to plan the tone for the specified length of time.
My guess is that SevenSeg is messing with the delayMicroseconds command and that's causing the problem.
Tim