Спойлер
#include <avr/pgmspace.h>
// by @tartakynov
// programmed for ATtiny13 in Arduino IDE using core13 http://sourceforge.net/projects/ard-core13/
#define PIN_LED 13
#define PIN_BUZZER 3
#define COUNT_NOTES 39
static const word frequences[COUNT_NOTES] PROGMEM = {
392, 392, 392, 311, 466, 392, 311, 466, 392,
587, 587, 587, 622, 466, 369, 311, 466, 392,
784, 392, 392, 784, 739, 698, 659, 622, 659,
415, 554, 523, 493, 466, 440, 466,
311, 369, 311, 466, 392 };
static const word durations[COUNT_NOTES] PROGMEM = {
350, 350, 350, 250, 100, 350, 250, 100, 700,
350, 350, 350, 250, 100, 350, 250, 100, 700,
350, 250, 100, 350, 250, 100, 100, 100, 200,
100, 350, 250, 100, 100, 100, 200,
100, 350, 250, 100, 750 };
void setup()
{
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_BUZZER, OUTPUT);
}
void loop()
{
for (byte i = 0; i < COUNT_NOTES; i++)
{
buzz(PIN_BUZZER, pgm_read_word(&(frequences[i])), 2 * pgm_read_word(&(durations[i])));
delay(100);
}
delay(1000);
}
void buzz(unsigned char pin, word frequencyInHertz, word timeInMilliseconds)
{
long delayAmount = (long)(long(1000000) / (long)frequencyInHertz);
long loopTime = (long)(((long)timeInMilliseconds * 500) / delayAmount);
for (long i = 0; i < loopTime; i++)
{
digitalWrite(pin, HIGH);
delayMicroseconds(delayAmount);
digitalWrite(pin, LOW);
delayMicroseconds(delayAmount);
}
}
пищит изумительно. И на ноге D3 и на выходе приёмника.