I guess that 100 should be absolutely maximum. Actually you know what? I'll post the code here.
int octave3[]={261,293,329,349,391,440,493};
int melody[]={};
int _position=0;
int note=0;
int length=0;
int button1=11;
int button2=12;
int button3=4;
int button4=3;
int button5=2;
int buzzer=6;
void setup(){
pinMode(button1,INPUT);
pinMode(button2,INPUT);
pinMode(button3,INPUT);
pinMode(button4,INPUT);
pinMode(button5,INPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
}
void loop(){
if(digitalRead(button2)==HIGH){
delay(200);
_position--;
if(_position<0) _position=0;
note=melody[_position];
tone(buzzer,melody[_position],180);
Serial.print("length ");
Serial.println(length);
Serial.print(" ");
Serial.print("_position ");
Serial.println(_position);
Serial.print(" ");
}
if(digitalRead(button3)==HIGH){
delay(200);
_position++;
if(_position==length) length++;
melody[length];
if(_position>=length) melody[_position]=octave3[note];
tone(buzzer,melody[_position],180);
Serial.print("length ");
Serial.println(length);
Serial.print(" ");
Serial.print("_position ");
Serial.println(_position);
Serial.print(" ");
}
if(digitalRead(button4)==HIGH){
delay(200);
note--;
if(note<0) note=0;
melody[_position]=octave3[note];
tone(buzzer,melody[_position],180);
}
if(digitalRead(button5)==HIGH){
delay(200);
note++;
if(note>6) note=6;
melody[_position]=octave3[note];
tone(buzzer,melody[_position],180);
}
if(digitalRead(button1)==HIGH){
delay(200);
//melody[_position]=octave3[note];
playMelody();
}
}
void playMelody(){
for(int cnt=0;cnt<length;cnt++){
tone(buzzer,melody[cnt],180);
delay(200);
noTone(buzzer);
if(digitalRead(button1)==HIGH) break;
}
}
Keep in mind that i'm a beginner, and I know that this is not a masterpiece.