Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/pgmspace.h>
- // by @tartakynov
- // programmed for ATtiny13 in Arduino IDE using core13 http://sourceforge.net/projects/ard-core13/
- #define PIN_LED 1
- #define PIN_BUZZER 0
- #define COUNT_NOTES 39
- 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 };
- 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(3000);
- }
- 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);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement