Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can anyone explain/break down whats going on in this arduino code? const int arr

ID: 3898668 • Letter: C

Question

Can anyone explain/break down whats going on in this arduino code?

const int arraySize=102;
char var11='0';
int array1[arraySize]={1153, 6708, 7944, 5668, 1490, 8124, 2196, 9530, 903, 7722, 4666, 8549, 8024, 7801, 6853, 977, 7408, 8228, 4933, 298, 8981, 8635, 8013, 3865, 9814, 9063, 4536, 9425, 1669, 4115, 94, 5629, 6501, 6517, 4195, 105, 404, 9451, 4298, 2188, 1123, 9505, 6882, 6752, 1566, 6716, 337, 4438, 21, 1501, 4897, 6807, 5249, 73, 3658, 8930, 1272, 7544, 878, 7923, 7709, 4440, 8165, 4492, 3042, 7987, 2503, 2327, 1729, 8840, 2612, 4303, 3169, 7709, 7157, 9560, 933, 3099, 278, 1816, 5335, 9097, 7826, 3512, 9267, 3810, 7633, 979, 9149, 6579, 8821, 1967, 672, 1393, 9336, 5485, 1745, 5228, 4091, 194, 6357, 5001 };
int function1(int var1a[]){
int var1b=var1a[0];
for (int i=1; i<arraySize;i=i+1){//POINTA
if (var1b<var1a[i]){
var1b=var1a[i];
}
}
return var1b;
}
void function2(int var2a, int var2b, int var2c){
digitalWrite(var2a,HIGH);
delay(250);
digitalWrite(var2a,LOW);
delay(250);
digitalWrite(var2b,HIGH);
delay(250);
digitalWrite(var2b,LOW);
delay(250);
digitalWrite(var2c,HIGH);
delay(250);
digitalWrite(var2c,LOW);
delay(1000);
}
void function3(){
int j=0;
while (j<100){
j=j*j+1;
}
}
float function4(float var4a){
if (var4a>20){//POINTB
int var4b=pow(var4a,3)/22.5+array1[22]-PI;
return var4b;
}
else{
delay(5);
return function4(var4a+PI);//POINTC
}
}
int function5(char var5){
if (var5='A'){
return 7;
}
if (var5='B'){
return 14;
}
if (var5='C'){
return 11;
}
}
void function6(int a[], int var6) {
for(int i=0; i<(var6-1); i++) {
for(int o=0; o<(var6-(i+1)); o++) {
if(a[o] > a[o+1]) {
int t = a[o];
a[o] = a[o+1];
a[o+1] = t;
}
  
}
}
}
int function7(int var7){
if (var7<3){
var7=var7+1;
}
else if (var7<9){
var7=function4(var7);
}
else if(var7>12){
var7=20;
}
return var7;
}
void function8(int baudrate){
Serial.println("This is the song that never ends, yes it goes on and on my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because...This is the song that never ends, yes it goes on and on my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because...This is the song that never ends, yes it goes on and on my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because...");
}
int function9(float var9){
var9=var9*10;
int var9Int=var9;
var9=var9-var9Int;
if (var9<.5){
var9=0;
}
else{
var9=1;
}
var9=(var9+var9Int)/10;
return(var9);
}
int function10(int var10a[], int var10b, int var10c){
int i=var10b;
int var10d=0;
while (i<=var10c){
var10d=var10d+var10a[i];
}
return var10d;
}
void function11(){
var11=var11+4;
}
void setup(){
Serial.begin(9600);
pinMode(11,OUTPUT);
analogWrite(11,95);
attachInterrupt(digitalPinToInterrupt(2), function11,CHANGE);
}
void loop(){
long int startTime=millis();
//PointD
long int endTime = millis()-startTime;
Serial.print("The endTime is ");
Serial.println(endTime);
Serial.print("analogpin3 is ");
Serial.println(analogRead(3));
delay (2000);
}

Explanation / Answer

const int arraySize=102;

char var11='0';

int array1[arraySize]={1153, 6708, 7944, 5668, 1490, 8124, 2196, 9530, 903, 7722, 4666, 8549, 8024, 7801, 6853, 977, 7408, 8228, 4933, 298, 8981, 8635, 8013, 3865, 9814, 9063, 4536, 9425, 1669, 4115, 94, 5629, 6501, 6517, 4195, 105, 404, 9451, 4298, 2188, 1123, 9505, 6882, 6752, 1566, 6716, 337, 4438, 21, 1501, 4897, 6807, 5249, 73, 3658, 8930, 1272, 7544, 878, 7923, 7709, 4440, 8165, 4492, 3042, 7987, 2503, 2327, 1729, 8840, 2612, 4303, 3169, 7709, 7157, 9560, 933, 3099, 278, 1816, 5335, 9097, 7826, 3512, 9267, 3810, 7633, 979, 9149, 6579, 8821, 1967, 672, 1393, 9336, 5485, 1745, 5228, 4091, 194, 6357, 5001 };

// This function will return largest number from the given array

int function1(int var1a[]){

                // Store first value from the array to variable

                int var1b=var1a[0];

                // Trace each values in array

                for (int i=1; i<arraySize;i=i+1){//POINTA

                                // Check if value at pos i in array is greatee than varlb then store that value in variable

                                if (var1b<var1a[i]){

                                                var1b=var1a[i];

                                }

                }

                // Return largest value

                return var1b;

}

void function2(int var2a, int var2b, int var2c){

                // digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin.

                digitalWrite(var2a,HIGH); // sets the digital pin var2a on

                delay(250); // waits for 250 millisecs

                digitalWrite(var2a,LOW); // sets the digital pin var2a off

                delay(250); // waits for 250 millisecs

                digitalWrite(var2b,HIGH); // sets the digital pin var2b on

                delay(250); // waits for 250 millisecs

                digitalWrite(var2b,LOW); // sets the digital pin var2b off

                delay(250); // waits for 250 millisecs

                digitalWrite(var2c,HIGH); // sets the digital pin var2c on

                delay(250); // waits for 250 millisecs

                digitalWrite(var2c,LOW); // sets the digital pin var2c off

                delay(1000); // waits for a second

}

void function3(){

                // initialize variable j to 0

                int j=0;

                // Loop will execute until j is less than 100

                while (j<100){

                                // Calculate new value for j

                                j=j*j+1;

                }

}

float function4(float var4a){ // recursive function

                if (var4a>20){//POINTB

                                int var4b=pow(var4a,3)/22.5+array1[22]-PI; // Make some calculation

                                return var4b; // Return calculated value

                }

                else{

                                delay(5); // waits for 5 millisecs

                                return function4(var4a+PI);//POINTC This recursively call itself until var4a becomes greater than 20

                }

}

int function5(char var5){

                // Check if var5 stores 'A' then return value 7

                if (var5='A'){

                                return 7;

                }

                // Check if var5 stores 'B' then return value 14

                if (var5='B'){

                                return 14;

                }

                // Check if var5 stores 'C' then return value 11

                if (var5='C'){

                                return 11;

                }

}

void function6(int a[], int var6) { // implements bubble sort

                for(int i=0; i<(var6-1); i++) {

                                // Last i elements are already in place  

                                for(int o=0; o<(var6-(i+1)); o++) {

                                                if(a[o] > a[o+1]) { // Check first value is greater than second then replace both

                                                                int t = a[o];

                                                                a[o] = a[o+1];

                                                                a[o+1] = t;

                                                }

                                }

                }

}

int function7(int var7){

                if (var7<3){ // If value of var7 is less than 3 then store var7 incremented by 1

                                var7=var7+1;

                }

                else if (var7<9){ // If value of var7 is greater or eqauls to 3 and less than 9 then call "function4"(Recursive function) and store value that function returns

                                var7=function4(var7);

                }

                else if(var7>12){ // If value of var7 is greater than 12 then store 20 as value

                                var7=20;

                }

                // Return new value of var7

                return var7;

}

void function8(int baudrate){

                // Prints data to the serial port as human-readable text

                Serial.println("This is the song that never ends, yes it goes on and on my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because...This is the song that never ends, yes it goes on and on my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because...This is the song that never ends, yes it goes on and on my friend. Some people started singing it, not knowing what it was, and they'll continue singing it forever just because...");

}

// This function will make some calculations and return calculated value

int function9(float var9){

                var9=var9*10;

                int var9Int=var9;

                var9=var9-var9Int;

                if (var9<.5){

                                var9=0;

                }

                else{

                                var9=1;

                }

                var9=(var9+var9Int)/10;

                return(var9);

}

// This function move to infinite loop if value of var10b <= var10c

int function10(int var10a[], int var10b, int var10c){

                int i=var10b;

                int var10d=0;

                while (i<=var10c){

                                var10d=var10d+var10a[i];

                }

                return var10d;

}

void function11(){

                var11=var11+4; // Store value to '4' as char

}

// The setup() function is called when a sketch starts.

void setup(){

                // Sets the data rate in bits per second (baud) for serial data transmission.

                Serial.begin(9600);

                // Sets the digital pin 11 as output

                pinMode(11,OUTPUT);

                // analogWrite(pin, value); Writes an analog value (PWM wave) to a pin

                analogWrite(11,95);

                // Digital Pins With Interrupts. When intrrupts occur(trigger the interrupt whenever the pin changes value) it will call "function11"

                attachInterrupt(digitalPinToInterrupt(2), function11,CHANGE);

}

// After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond.

void loop(){

                long int startTime=millis();

                //PointD

                long int endTime = millis()-startTime;

                Serial.print("The endTime is ");

                Serial.println(endTime);

                Serial.print("analogpin3 is ");

                Serial.println(analogRead(3));

                delay (2000);

}