Skip to content

Instantly share code, notes, and snippets.

@rdev5
Created April 8, 2016 08:22
Show Gist options
  • Save rdev5/a8867a02a82344a56874e52df884c401 to your computer and use it in GitHub Desktop.
Save rdev5/a8867a02a82344a56874e52df884c401 to your computer and use it in GitHub Desktop.
/* TinyTone for ATtiny85 (thanks to http://www.technoblogy.com/show?KVO) */
// Notes
const int Note_C = 239;
const int Note_CS = 225;
const int Note_D = 213;
const int Note_DS = 201;
const int Note_E = 190;
const int Note_F = 179;
const int Note_FS = 169;
const int Note_G = 159;
const int Note_GS = 150;
const int Note_A = 142;
const int Note_AS = 134;
const int Note_B = 127;
const int Note_Rest = 0;
int Speaker = 1;
const float Tempo = 250;
const int Pitch = 1;
void setup()
{
pinMode(Speaker, OUTPUT);
delay(1000);
playTune();
}
void loop()
{
}
void TinyTone(unsigned char divisor, float duration, int octave)
{
octave += Pitch;
duration *= Tempo;
if (divisor == Note_Rest)
{
delay(duration);
return;
}
TCCR1 = 0x90 | (8-octave); // for 1MHz clock
// TCCR1 = 0x90 | (11-octave); // for 8MHz clock
OCR1C = divisor-1; // set the OCR
delay(duration);
TCCR1 = 0x90; // stop the counter
}
// Spring (from "The Four Seasons") by Antonio Vivaldi (transposed for Arduino by Matt Borja)
void playTune(void)
{
// m. 1
TinyTone(Note_C, 1, 4);
// m. 2
TinyTone(Note_E, 1, 4);
TinyTone(Note_E, 1, 4);
TinyTone(Note_E, 1, 4);
TinyTone(Note_D, 0.5, 4);
TinyTone(Note_C, 0.5, 4);
// m. 3
TinyTone(Note_G, 3, 4);
TinyTone(Note_G, 0.5, 4);
TinyTone(Note_F, 0.5, 4);
// m. 4
TinyTone(Note_E, 1, 4);
TinyTone(Note_E, 1, 4);
TinyTone(Note_E, 1, 4);
TinyTone(Note_D, 0.5, 4);
TinyTone(Note_C, 0.5, 4);
// m. 5
TinyTone(Note_G, 3, 4);
TinyTone(Note_G, 0.5, 4);
TinyTone(Note_F, 0.5, 4);
// m. 6
TinyTone(Note_E, 1, 4);
TinyTone(Note_F, 0.5, 4);
TinyTone(Note_G, 0.5, 4);
TinyTone(Note_F, 1, 4);
TinyTone(Note_E, 1, 4);
// Skip to m. 13
TinyTone(Note_D, 2, 4);
TinyTone(Note_Rest, 1, 4);
TinyTone(Note_E, 1, 4);
// m. 14
TinyTone(Note_G, 1, 4);
TinyTone(Note_F, 0.5, 4);
TinyTone(Note_E, 0.5, 4);
TinyTone(Note_F, 1, 4);
TinyTone(Note_G, 1, 4);
// m. 15
TinyTone(Note_A, 1, 4);
TinyTone(Note_G, 2, 4);
TinyTone(Note_C, 1, 4);
// m. 16
TinyTone(Note_G, 1, 4);
TinyTone(Note_F, 0.5, 4);
TinyTone(Note_E, 0.5, 4);
TinyTone(Note_F, 1, 4);
TinyTone(Note_G, 1, 4);
// m. 17
TinyTone(Note_A, 1, 4);
TinyTone(Note_G, 2, 4);
TinyTone(Note_C, 1, 4);
// m. 18
TinyTone(Note_A, 1, 4);
TinyTone(Note_G, 2, 4);
TinyTone(Note_F, 1, 4);
// m. 19
TinyTone(Note_E, 1, 4);
TinyTone(Note_D, 0.5, 4);
TinyTone(Note_C, 0.5, 4);
TinyTone(Note_D, 1, 4);
TinyTone(Note_D, 1, 4);
// m. 20
TinyTone(Note_C, 2, 4);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment