#include <CircularBuffer.h>

const int size = 300;

CircularBuffer<float, size> buffer;
CircularBuffer<int, 10> variation;


float prev;
int test;


int peak(int pos)
{
  int sum=0;
  if(buffer[pos] > buffer[pos-1])
  {
    variation.push(1);
  }
  else if(buffer[pos] < buffer[pos-1])
  {
    variation.push(-1);
  }



  for(int i=0; i<10; i++)
  {
    sum += variation[i];
    // Serial.print(variation[i]);
    // Serial.print(" ");
  }

  // Serial.println();

  return sum;
}


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.println("Hello, ESP32!");


 

  for(float i=0; i<size; i ++)
  {
    buffer.push(sin(i/10));

   
  }


  for(float i=0; i<size; i ++)
  {
    test = peak(i);
    if ((test >= -1) && (test <=1))
    {
      Serial.print("**** PEAK:   ");
      Serial.println(buffer[i-4]);
    }
    
    Serial.print(buffer[i]);
    Serial.print("  ");
    Serial.println(test);
  }





}

void loop() {
  // put your main code here, to run repeatedly:
  delay(10); // this speeds up the simulation
}