/* Digital Music Box v2 David Johnson-Davies - www.technoblogy.com - 16th March 2016 ATtiny85 @ 16 MHz (internal PLL; 4.3 V BOD) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ int Scale[] = { 680, 721, 764, 809, 857, 908, 962, 1020, 1080, 1144, 1212, 1284, 1361, 1442, 1528, 1618, 1715, 1817, 1925, 2039, 2160, 2289, 2425, 2569, 2722, 2884, 3055, 3237, 3429, 3633, 3849, 4078 }; const int Channels = 4; const int Tempo = 4; // 4 = 4 beats per second const int Decay = 9; // Length of note decay; max 10 volatile unsigned int Acc[Channels]; volatile unsigned int Freq[Channels]; volatile unsigned int Amp[Channels]; // Play Happy Birthday const uint32_t Tune[] PROGMEM = { //_*_*__*_*_*__*_*__*_*_*__*_*__*_ //C D EF G A BC D EF G A BC D EF G 0b00000000000000000001000000000000, 0b00000000000000000001000000000000, 0b10000000000000000000010000000000, 0b00000000000000000000000000000000, 0b00001001000000000001000000000000, 0b00000000000000000000000000000000, 0b00000000000000000000000010000000, 0b00000000000000000000000000000000, 0b00100000000000000000000100000000, 0b00000000000000000000000000000000, 0b00000101000000000000000000000000, 0b00000000000000000000000000000000, 0b00000000000000000001000000000000, 0b00000000000000000001000000000000, 0b10000000000000000000010000000000, 0b00000000000000000000000000000000, 0b00000101000000000001000000000000, 0b00000000000000000000000000000000, 0b00000000000000000000000000100000, 0b00000000000000000000000000000000, 0b10000000000000000000000010000000, 0b00000000000000000000000000000000, 0b00001001000000000000000000000000, 0b00000000000000000000000000000000, 0b00000000000000000001000000000000, 0b00000000000000000001000000000000, 0b10000000000000000000000000000001, 0b00000000000000000000000000000000, 0b00100000000000000000000000001000, 0b00000000000000000000000000000000, 0b00001000000000000000000010000000, 0b00000000000000000000000000000000, 0b00000100000000000000000100000000, 0b00000000000000000000000000000000, 0b00000000000000000000010000000000, 0b00000000000000000000000000000000, 0b00000000000000000000000000000100, 0b00000000000000000000000000000100, 0b00000001000000000000000000001000, 0b00000000000000000000000000000000, 0b00000000000000000000000010000000, 0b00000000000000000000000000000000, 0b00000101000000000000000000100000, 0b00000000000000000000000000000000, 0b10001001000000000000000010000000, 0xFF}; // End of tune //Globals persist throughout tune int TunePtr = 0, Chan = 0; // Watchdog interrupt plays notes ISR(WDT_vect) { sei(); // Allow interrupts WDTCR |= 1<> 8; Mask = Temp >> 7; Env = Amp[c] >> Decay; Note = (Env ^ Mask) + (Mask & 1); Sum = Sum + Note; } OCR1B = Sum + 128; } void setup() { // Enable 64 MHz PLL and use as source for Timer1 PLLCSR = 1<