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() {
void loop() {
  if (Vc>Valpha) //comparator
  if (Vd<Valpha) //Comparator
    }//    Vj=1;}else{Vj=0;}

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

// Serial.print("Vc:");
// Serial.println(Vc);
// 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);

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