OK, I have a little hardware issue I need to fix in software for the time being. I say, "For the time being," because I already have the PC Boards printed, and I need to make do for this run of boards. (So sue me for not bread boarding first.) I THOUGHT the little buzzers I purchased sounded off on a DC input, but I was wrong. I used the nearest pin to the buzzer to activate it, which is D14. The next run of boards I will use A6 instead, but until then I will need to output a square wave of about 2731 Hz on D14 of an ATTiny88. The straightforward approach would seem to be something like:
bool buzzer(bool x) {
if (x) {
return true;
}
return false;
}
bool PinVal = false;
void loop() {
<some code here>
buzzerVal = buzzer(true | false);
<some code here>
if (buzzerVal && micros()%376 > 365) {
PinVal = !PinVal;
digitalWrite`(14,PinVal);
}
while (micros()%376 > 365);
}
Is there a smarter, more efficient way? If so, I might consider not even changing the board layout. Pin 14 has an alternate function of register PB7. It occurs to me it might be more efficient to write directly to PB7, rather than using the digitalWrite function, which presumably has more overhead. Yes? No? Any other ideas?