/* Tiny Synth v5 David Johnson-Davies - www.technoblogy.com - 6th November 2017 ATtiny85 @ 8MHz (internal oscillator; BOD disabled) CC BY 4.0 Licensed under a Creative Commons Attribution 4.0 International license: http://creativecommons.org/licenses/by/4.0/ */ int Scale[] = { 0,13717,14532,15397,16312,17282,0,18310,19398,20552,21774,23069,24440,25894,0}; const int Silence = 0; const int Error = 0; // Error LED on PB0 // Note buffer volatile unsigned int Acc[] = {Silence, Silence, Silence, Silence}; volatile unsigned int Freqs[] = {0, 0, 0, 0 }; const char Tune[] PROGMEM = "C(-1:C)Fe 2,dE | 4,F(-1:D) 2,eF 4,A(-1:G)g | 2,f(-1:F)eF(-1:E)G 4,f(-1:D)e(-1:C) |" "2,d(-2:B)Edc 4,b(-2:G)G | c(-1:C)Fe 2,dE | 4,F(-1:D) 2,eF 4,A(-1:G)g |" "2,A(-1:F)gA(-1:E)Cb(-1:G)gB(-1:B)D | 4,c(-1:C)g 8,C ^(^^)"; //Globals persist throughout tune unsigned int NextTick = 0; int TunePtr = 0; int Octave = 0, LastIndex = 0, Duration = 4; // Global tick counter volatile unsigned int GlobalTicks = 0; // Ticks timer unsigned int Ticks() { unsigned long t; uint8_t oldSREG = SREG; cli(); t = GlobalTicks; SREG = oldSREG; return t; } // Watchdog interrupt counts ticks (1/8 sec) ISR(WDT_vect) { WDTCR |= 1<> 8; Mask = Temp >> 15; Sum = Sum + ((char)(Temp ^ Mask) >> 1); } OCR1B = Sum; } // Setup ********************************************** void setup() { // Enable 64 MHz PLL and use as source for Timer1 PLLCSR = 1<= '0') && (Symbol <= '9')) Number = Number*10 + Symbol - '0'; else if (Symbol == '<') Octave--; else if (Symbol == '>') Octave++; else if (Symbol == '-') Sign = -1; else if (Symbol == '+') Sign = 1; else if (Symbol == '/') ReadNote = 1; else if (Symbol == '^') { Acc[Chan] = Silence; Freqs[Chan++] = 0; ReadNote = 1; } else if ((CapSymbol >= 'A') && (CapSymbol <= 'G')) { boolean Lowercase = (Symbol & 0x20); int Index = (((CapSymbol - 'A' + 5) % 7) << 1) + 1 + Sign; if (!SetOctave) { if (LastIndex && (Index < LastIndex) && !Lowercase) Octave++; if (LastIndex && (Index > LastIndex) && Lowercase) Octave--; } else SetOctave = 0; Freqs[Chan++] = Scale[Index] >> (4 - Octave); LastIndex = Index; ReadNote = 1; Sign = 0; } else digitalWrite(Error, 1); // Illegal character } while (More); TunePtr--; NextTick = NextTick + Duration; while (Ticks() < NextTick); }