We’re rewarding the question askers & reputations are being recalculated! Read more.
2

I tried the code on an Uno and as you say, it does sound odd. By my calculations, the frequency is 40kHz (16MHz/(200 x 2)), which is above the threshold of hearing. The sound we are actually hearing is probably the 3rd or 5th harmonic, at a reduced intensity and perhaps subject to jitter. I tried changing TCCR2B = _BV(CS20); // clk/1 to TCCR2B = _BV(...


1

Looks like my tone frequency was possibly just too high for the buzzer I was using, causing strange output. Adjusting the clock divider fixed the issue. That is, I changed the following: TCCR2B = _BV(CS20); // clk/1 to TCCR2B = _BV(CS22) | _BV(CS20); // clk/128 and now I get reasonable-sounding tones. Note that the clock divider you choose is ...


1

This: led* redLed; defines a global variable implicitly initialized to zero (i.e. a NULL pointer). This is an invalid pointer you are not allowed to use until you properly initialize it. Here: redLed->pin = 3; you are writing to the memory pointed to by this invalid pointer. This invokes what the C and C++ standards call undefined behavior. What that ...


1

This is just a partial, rushed answer. You should be able to get a significant speed-up if you define your own ISR for handling the interrupt, as in: ISR(INT1_vect) { ... } The Arduino way of using interrupts is instead void trigger() { ...} void setup() { attachInterrupt(int_number, trigger, CHANGE); ... } but this is slow, as it involves the ...


Only top voted, non community-wiki answers of a minimum length are eligible