How program Zero Crossing detection sine wave and integrate.

Hi, everyone


Fig. 1

I need control and integrate the sine wave in arduino Mega or Due as figure 1, my code is below:
thanks for suggestions.

int tiempo,x;
float Va,Vb,Vc,Vd,Vi,Vj,deltaT=0.1;
float T=1e6/60.0;
float Vbant,Valpha=0.8;
void setup() {
  Serial.begin(9600);
  pinMode(A0,INPUT);
  pinMode(A1,INPUT); 
  pinMode(13,OUTPUT);
}
void loop() {
  tiempo=micros();   
  Va=sin(2*3.1416/T*micros());
  Vb=deltaT/1e6*Va+Vbant;
  Vc=1+Vb;
  Vd=1-Vb;
 
  if (Vc>Valpha) //comparator
  {
    Vi=1;digitalWrite(13,HIGH);
    }
  else
  {
    Vi=0;digitalWrite(13,LOW);
  }
   
  if (Vd<Valpha) //Comparator
  {
    Vj=1;digitalWrite(12,HIGH);
    }
  else
  {
    Vj=0;digitalWrite(12,LOW);
    }//    Vj=1;}else{Vj=0;}
  Vbant=Vb;

//if (!Vk)                  // Complemet(complemento)
//if (Vj == HIGH  && Vk == LOW) // AND gate



  //Serial.println("Va+1:");
  //Serial.println(Va+1);
  //Serial.println(analogRead(A1));
 //Serial.println(Va);
// Serial.print("Vc:");
// Serial.println(Vc);
 //Serial.print("Vd:");
 //Serial.println(Vd);
// Serial.print("Vi:"); Serial.println(Vi); Serial.print("Vj:");Serial.println(Vj);
 //Serial.print(" ") ;Serial.println("Valpha:");  Serial.println(Valpha);
  //Serial.println("Vd:");Serial.print(Vd);  Serial.print(" "); Serial.println("Valpha:"); Serial.println(Valpha);
  deltaT=(micros()-tiempo);
}

my code is below:

It does something.
You expect it to do something.
Those two things may or may not be the same thing.

You left out a lot of details from your post.

BTW, normally a comparator has some positive feed back to prevent noise from creating multiple transitions at zero crossing.

.

I want to make Zero Crossing Detection for sinusoidal signal using GY 521 with Arduino Uno ATMEGA 328. Help me for the program to make frequency, 1/2 wave. I need for my project. thanks before