//Example sketch on how to use array's for JColvin91's //Instructable on "Creating and Using an Array 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 [50]; int onOrOff [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 i=0; int j=0; int startTime; //setting all of the array element values to 0, //in case we are starting a new recording for(int arrayValue=0; arrayValue<50; arrayValue++){ recording[arrayValue] = {0}; }//end of erasing the previous recording //turn on the recoding LED 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 onOrOff[j] = 0; //storing that this was a time when the button was not pressed recording[i] = millis()-startTime; //store the time difference to an array value j++;//increment to the next spot in the array i++;//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){ onOrOff[j] = 1; //storing that this was a time when the button was pressed recording[i] = millis()-startTime; j++;//incrementing i++;//incrementing }//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 i = 0; int j = 0; while(playState == true){ for(i=0; i<50; i++){ //looping through the array //checking to see if the recording has ended since it only records if the action lasted longer than 1ms if(onOrOff[j] == 0 && recording[i] == 0){ j=50; i=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(onOrOff[j] == 0){ startTime = millis(); while((millis()-startTime)