I’ve been really studying your brat code’s functionality and flow; I’ve also learned a lot about timers and interrupts in the last couple of days.
I’ve written my own Groupmove handler that uses a lot of the same ideas in your code and it’s working great. Now my question is… How do you generate a tone without timer2…
You will notice this somewhere in each of my programs…
[code]// BUGBUG:: Move to some library…
//==============================================================================
// SoundNoTimer - Quick and dirty tone function to try to output a frequency
// to a speaker for some simple sounds.
//==============================================================================
void SoundNoTimer(uint8_t _pin, unsigned long duration, unsigned int frequency)
{ #ifdefAVR
volatile uint8_t *pin_port;
volatile uint8_t pin_mask; #else
volatile uint32_t *pin_port;
volatile uint16_t pin_mask; #endif
long toggle_count = 0;
long lusDelayPerHalfCycle;
// Set the pinMode as OUTPUT
pinMode(_pin, OUTPUT);
pin_port = portOutputRegister(digitalPinToPort(_pin));
pin_mask = digitalPinToBitMask(_pin);
toggle_count = 2 * frequency * duration / 1000;
lusDelayPerHalfCycle = 1000000L/(frequency * 2);
// if we are using an 8 bit timer, scan through prescalars to find the best fit
while (toggle_count--) {
// toggle the pin
*pin_port ^= pin_mask;
// delay a half cycle
delayMicroseconds(lusDelayPerHalfCycle);
}
*pin_port &= ~(pin_mask); // keep pin low after stop
}
void MSound(uint8_t _pin, byte cNotes, …)
{
va_list ap;
unsigned int uDur;
unsigned int uFreq;
va_start(ap, cNotes);
Well awhile ago BIll suggested that I set my self up with GIT and clone the project and the like, such that he can look at the changes and simply apply the changes…
So I now have it setup (I think) and the change are up there waiting for him to notice and maybe apply the changes.