Sorry, I should have specified my queries earlier.
I've highlighted the parts which I havent understood and typed my query besides it.
const int xpin = A0; // x-axis of the accelerometer
const int ypin = A1; // y-axis
const int numReadings = 40;
int readings1[numReadings];
int readings2[numReadings];// the readings from the analog input
int index = 0;// the index of the current reading
int total1 = 0;
int total2 = 0; // the running total
int average1 = 0;
int average2 = 0;// the average
int inputPin1 = xpin;
int inputPin2 = ypin;
float result1 = 0;
float result2 = 0;
int result3 = 0;
float result4 = 0;
float result5 = 0;
int result6 = 0; Why has the declared these values?
int num0 = 0;
int num1 = 1;
int num2 = 2;
int num3 = 3;
int num4 = 4;
int num5 = 5;
int num6 = 6;
int num7 = 7;
int num8 = 8;
void setup(){
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings1[thisReading] = 0;
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings2[thisReading] = 0;
}
void loop(){
// subtract the last reading:
total1= total1 - readings1[index];
total2= total2 - readings2[index];
// read from the sensor:
readings1[index] = analogRead(inputPin1);
readings2[index] = analogRead(inputPin2);
// add the reading to the total:
total1= total1 + readings1[index];
total2= total2 + readings2[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
average1 = total1 / numReadings;
average2 = total2 / numReadings;
// send it to the computer (as ASCII digits)
result1 = (average1 - 318)/(float)159;
if(result1>1) result1=1;
if(result1<-1) result1=-1;
result2 = asin(result1);
result3 = result2 * 57.32;
result4 = (average2 - 344)/(float)172;
if(result4>1) result4=1;
if(result4<-1) result4=-1;
result5 = asin(result4);
result6 = result5 * 57.32; I havent understood this part entirely. Why is he subtracting specific values like 318 and 344 from the averages and divide by 159 and 172 repectively? Why is he multiplying result3 and 5 with 57.32? and why is result2 or 5 = asin(result1 or 4)?
////////////Transmission//////////
/////////Forward//////////
if(result3 >= 11 && result3 <= 20){
Serial.print(num1);
}
Why specific values like 11 and 21? and why is he only using result3?
if(result3 >= 21 && result3 <= 30){
Serial.print(num2);
}
if(result3 >= 31 && result3 <= 40){
Serial.print(num3);
}
if(result3 >= 41 && result3 <= 50){
Serial.print(num4);
}
if(result3 >= 51 && result3 <= 60){
Serial.print(num5);
}
if(result3 >= 61 && result3 <= 70){
Serial.print(num6);
}
if(result3 >= 71 && result3 <= 80){
Serial.print(num7);
}
if(result3 >= 81 && result3 <= 90){
Serial.print(num8);
}
////////////Backward////////////
if(result3 >= -20 && result3 <= -11){
Serial.print("a");
}
if(result3 >= -30 && result3 <= -21){
Serial.print("b");
}
if(result3 >= -40 && result3 <= -31){
Serial.print("c");
}
if(result3 >= -50 && result3 <= -41){
Serial.print("d");
}
if(result3 >= -60 && result3 <= -51){
Serial.print("e");
}
if(result3 >= -70 && result3 <= -61){
Serial.print("f");
}
if(result3 >= -80 && result3 <= -71){
Serial.print("g");
}
if(result3 >= -90 && result3 <= -81){
Serial.print("h");
}
////////////////Left//////////////
if(result6 >= 11 && result6 <= 20){
Serial.print("i");
}
Why result6 now?
if(result6 >= 21 && result6 <= 30){
Serial.print("j");
}
if(result6 >= 31 && result6 <= 40){
Serial.print("k");
}
if(result6 >= 41 && result6 <= 50){
Serial.print("l");
}
if(result6 >= 51 && result6 <= 60){
Serial.print("m");
}
if(result6 >= 61 && result6 <= 70){
Serial.print("n");
}
if(result6 >= 71 && result6 <= 80){
Serial.print("o");
}
if(result6 >= 81 && result6 <= 90){
Serial.print("p");
}
////////////Right////////////////
if(result6 >= -20 && result6 <= -11){
Serial.print("q");
}
if(result6 >= -30 && result6 <= -21){
Serial.print("r");
}
if(result6 >= -40 && result6 <= -31){
Serial.print("s");
}
if(result6 >= -50 && result6 <= -41){
Serial.print("t");
}
if(result6 >= -60 && result6 <= -51){
Serial.print("u");
}
if(result6 >= -70 && result6 <= -61){
Serial.print("v");
}
if(result6 >= -80 && result6 <= -71){
Serial.print("w");
}
if(result6 >= -90 && result6 <= -81){
Serial.print("x");
}
}