//Example sketch on how to use array's for JColvin91's //Instructable on "Creating and Using Multidimensional Arrays in C++" //global variables //record button, recording state, and record LED int recordB = 5; boolean recordState = false; int recordBL = 31; //button to turn on the middle LED, middle LED int ledB = 7; int midLED = 33; //play button, playing state, and play LED int playB = 9; boolean playState = false; int playBL = 35; //arrays of 50 elements to store the recording and the on/off state int recording [2][50]; //end of globals void setup(){ //setting the pins to inputs or outputs pinMode(recordB, INPUT); pinMode(recordBL, OUTPUT); digitalWrite(recordBL, LOW); pinMode(playB, INPUT); pinMode(playBL, OUTPUT); digitalWrite(playBL, LOW); pinMode(ledB, INPUT); pinMode(midLED, OUTPUT); digitalWrite(midLED, LOW); }//end of setup() void loop(){ while(digitalRead(ledB)==LOW && digitalRead(recordB)==LOW && digitalRead(playB)==LOW){ //do nothing } //if the record button is pressed if(digitalRead(recordB)==HIGH){ while(digitalRead(recordB)==HIGH){} recordState=true; record(); //go to the record function } //if the play button is pressed if(digitalRead(playB)==HIGH){ while(digitalRead(playB)==HIGH){} playState=true; play(); //go to the play function } //if the middle button is pressed if(digitalRead(ledB)==HIGH){ digitalWrite(midLED, HIGH); while(digitalRead(ledB)==HIGH){ //wait and keep the LED on } digitalWrite(midLED, LOW); }//end of if middle button is pressed }//end of loop() void record(){ digitalWrite(recordBL, HIGH); //setting up some variables that we will need int j=0; int startTime; //setting all of the array element values to 0, //in case we are starting a new recording for(int arrayLayer = 0; arrayLayer<2; arrayLayer++){ for(int arrayValue=0; arrayValue<50; arrayValue++){ recording[arrayLayer][arrayValue] = 0; }//end of erasing the previous recording } while(recordState==true){//while we are recording startTime = millis();//getting the current time while(digitalRead(ledB)==LOW && digitalRead(recordB)==LOW){ //wait while no buttons are pressed } if((millis()-startTime)>1){//if the time that no button was pressed was longer than 1 millisecond, to make sure that we don't record weird stuff recording[0][j] = 0; //no button was pressed recording[1][j] = millis()-startTime; //time it was not pressed for j++;//increment to the next spot in the array } //if the middle button is pressed... if(digitalRead(ledB)==HIGH){ digitalWrite(midLED, HIGH);//turn on the middle LED startTime = millis();//getting the current time while(digitalRead(ledB)==HIGH){ //wait while the button is pressed } if((millis()-startTime)>1){ recording[0][j] = 1; //button was pressed recording[1][j] = millis()-startTime; //time it was not pressed for j++;//increment to the next spot in the array }//end checking to see if the button was pressed long enough digitalWrite(midLED, LOW); }//end of if the middle button was pressed //if the recording button is pressed to stop recording... if(digitalRead(recordB)==HIGH){ while(digitalRead(recordB)==HIGH){} delay(5); recordState=false; }//end of if recording button was pressed }//end of while recordState is true digitalWrite(recordBL, LOW); }//end of record() void play(){ digitalWrite(playBL, HIGH); int startTime; int j = 0; while(playState == true){ for(j=0; j<50; j++){ //looping through the array //checking to see if the recording has ended since it only records if the action lasted longer than 1ms if(recording[1][j] == 0){ j=50; delay(10); }//if we encounter unused array space, the recording must have ended so we jump to the end of the array //if the button was not pressed... if(recording[0][j] == 0){ startTime = millis(); while((millis()-startTime)