/* *This code is for an attiny85 powered pocket sequencer and is part of an *instructable at http://www.instructables.com/id/Attiny-Pocket-Sequencer/ . * *The following code was written by: Adam Berger * *You are free to use my code in anyway you'd like, as long as *you give credit where it is due. Thank you for your interest! */ const byte pot = 3, latch = 0, data = 2, clock = 1, speaker = 4; const int MAX_NOTE_LENGTH = 3000, MAX_FREQ = 10000, NUMBER_OF_STEPS = 8, POT_THRESHOLD = 25; int stepFreqs[] = {500,440,500,440,440,660,395,440}; int stepSustains[] = {100,100,100,100,100,100,100,100}; int tempo = 1000; unsigned long previousMillis, functionMillis; void setup(){ //enable inpustepFreqsts pinMode(pot, INPUT); digitalWrite(pot, HIGH); //enable outputs pinMode(data, OUTPUT); pinMode(clock, OUTPUT); pinMode(latch, OUTPUT); //start up sound tone(speaker, 659, 75); delay(100); tone(speaker, 523, 75); delay(100); tone(speaker, 659, 75); delay(100); tone(speaker, 784, 75); delay(100); //set notes setFrequencies(); } void loop(){ //for each step for(byte a=0; a500)) setSustain(); } noTone(speaker); } } void setFrequencies(){ for(byte a=0; aPOT_THRESHOLD)){ previousMillis=millis(); int freq = map(analogRead(pot),POT_THRESHOLD,1023,0, MAX_FREQ); if(analogRead(pot)POT_THRESHOLD)){ stepSustains[a] = map(analogRead(pot),POT_THRESHOLD,1023,0, MAX_NOTE_LENGTH); tone(speaker, stepFreqs[a], stepSustains[a]); functionMillis=millis(); while(millis()-functionMillis<(stepSustains[a]+(stepSustains[a]/2))){ if(analogRead(pot)