Help sruggle correct the code

boolean clipping = 0;
byte newData = 0;
byte prevData = 0;
unsigned int time = 0;//keeps time and sends vales to store in timer occasionally
int timer[10];//storage for timing of events
int slope[10];//storage for slope of events
unsigned int totalTimer;//used to calculate period
unsigned int period;//storage for period of wave
byte index = 0;//current storage index
float frequency;//storage for frequency calculations
int maxSlope = 0;//used to calculate max slope as trigger point
int newSlope;//storage for incoming slope data
//variables for decided whether you have a match
byte noMatch = 0;//counts how many non-matches you’ve received to reset variables if it’s been too long byte slopeTol = 3;//slope tolerance- adjust this if you need
int timerTol = 10;//timer tolerance- adjust this if you need
//variables for amp detection
unsigned int ampTimer = 0;
byte maxAmp = 0;
byte checkMaxAmp;
byte ampThreshold = 30;//raise if you have a very noisy signal
#include <Stepper.h>
Stepper stepper(STEPS, 8, 9, 10, 11);

int freq=“desired Frequency”
void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT);//led indicator pin
pinMode(12,OUTPUT);//output pin
stepper.setSpeed(5);
cli();//diable interrupts
//set up continuous sampling of analog pin 0 at 38.5kHz
//clear ADCSRA and ADCSRB registers
ADCSRA = 0;
ADCSRB = 0;
ADMUX |= (1 << REFS0); //set reference voltage
ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz
ADCSRA |= (1 << ADATE); //enabble auto trigger
ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
ADCSRA |= (1 << ADEN); //enable ADC
ADCSRA |= (1 << ADSC); //start ADC measurements
sei();//enable interrupts
}
ISR(ADC_vect) {//when new ADC value ready
PORTB &= B11101111;//set pin 12 low
prevData = newData;//store previous value
newData = ADCH;//get value from A0
if (prevData < 127 && newData >=127){//if increasing and crossing midpoint
newSlope = newData - prevData;//calculate slope
if (abs(newSlope-maxSlope)<slopeTol){//if slopes are ==
//record new data and reset time
slope[index] = newSlope;
timer[index] = time;
time = 0;
if (index == 0){//new max slope just reset
PORTB |= B00010000;//set pin 12 high
noMatch = 0;
index++;//increment index
}
else if (abs(timer[0]-timer[index])<timerTol && abs(slope[0]-newSlope)<slopeTol){//if timer duration and slopes match
//sum timer values
totalTimer = 0;
for (byte i=0;i<index;i++){
totalTimer+=timer*; *
*} *
period = totalTimer;//set period
*//reset new zero index values to compare with *
timer[0] = timer[index];
slope[0] = slope[index];
index = 1;//set index to 1
*PORTB |= B00010000;//set pin 12 high *
*noMatch = 0; *
}
*else{//crossing midpoint but not match *
*index++;//increment index if (index > 9){ *
*reset(); *
*} *
*} *
*} *
*else if (newSlope>maxSlope){//if new slope is much larger than max slope *
maxSlope = newSlope;
time = 0;//reset clock
*noMatch = 0; *
*index = 0;//reset index *
*} *
*else{//slope not steep enough *
*noMatch++;//increment no match counter *
*if (noMatch>9){ *
*reset(); *
*} *
*} *
*} *
*if (newData == 0 || newData == 1023){//if clipping *
*clipping = 1;//currently clipping *
*Serial.println(“clipping”); *
*} *
*time++;//increment timer at rate of 38.5kHz *
*ampTimer++;//increment amplitude timer *
*if (abs(127-ADCH)>maxAmp){ *
*maxAmp = abs(127-ADCH); *
*} *
*if (ampTimer==1000){ *
*ampTimer = 0; *
*checkMaxAmp = maxAmp; *
*maxAmp = 0; *
*} *
*} *
*void reset(){//clean out some variables *
index = 0;//reset index
*noMatch = 0;//reset match couner *
*maxSlope = 0;//reset slope *
}
*void checkClipping(){//manage clipping indication *
*if (clipping){//if currently clipping *
*clipping = 0; *
*} *
*} *
*void loop(){ *
checkClipping();
*if (checkMaxAmp>ampThreshold){ *
*int frequency = 38462/float(period);//calculate frequency timer rate/period *
if (freq - 10 > frequency)
{
*for ( int i=0 ; i<100 ; i=i+1){ *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*} *
*delay(1000); *
*} *
*if (freq - 5 > frequency) *
*{ *
*for ( int i=0 ; i<50 ; i=i+1){ *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*} *
*delay(6000); *
*} *
*if (freq + 10 < frequency) { *
*for ( int i=0 ; i<100 ; i=i+1){ *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*} *
*delay(1000); *
*} *
if (freq + 5 < frequency) {
*for ( int i=0 ; i<50 ; i=i+1){ *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*digitalWrite(motorPin1, LOW); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, HIGH); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, HIGH); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, LOW); *
*delay(3); *
*digitalWrite(motorPin1, HIGH); *
*digitalWrite(motorPin2, LOW); *
*digitalWrite(motorPin3, LOW); *
*digitalWrite(motorPin4, HIGH); *
*delay(3); *
*} *
*delay(6000); *
*} *
*} *
*delay(100); *
*} *

what is the code expected to do?
what does the code do wrong?

@maitsos

Please follow the advice on posting code given in Read this before posting a programming question in order to make your sketch easy to read, copy and test

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

If the code exceeds the 9000 character inline limit then attach it to a post

When you indent the code and format it you see that there's a segment between the ISR and reset() functions that is "orphan". Where is is supposed to go?

.
.
.
}//ISR

if (newData == 0 || newData == 1023) { //if clipping
  clipping = 1;//currently clipping
  Serial.println("clipping");
}
time++;//increment timer at rate of 38.5kHz
ampTimer++;//increment amplitude timer
if (abs(127 - ADCH) > maxAmp) {
  maxAmp = abs(127 - ADCH);
}
if (ampTimer == 1000) {
  ampTimer = 0;
  checkMaxAmp = maxAmp;
  maxAmp = 0;
}
}


void reset() 
.
.
.

Your definition of ‘STEPS’ is missing. That should be the number of steps per revolution of your stepper. 200 is a common value.
This line is missing the ending ‘;’ and you can’t give an integer a string value. Pick a frequency!

int freq = "desired Frequency"

You didn’t create the variable ‘slopeTol’:

    if (abs(newSlope - maxSlope) < slopeTol) //if slopes are ==

There appears to be an extra ‘}’ in here so the function ‘reset()’ never gets defined:

    {
      reset();
    }
  }
}
if (newData == 0 || newData == 1023) //if clipping
{

Here you are comparing the byte variable ‘newData’ against 1023. Since a byte can only go up to 255 this will always be false and shows a misunderstanding somewhere:

  if (newData == 0 || newData == 1023) //if clipping

Here is a version corrected to only show one warning:

boolean clipping = 0;
byte newData = 0;
byte prevData = 0;
unsigned int time = 0;//keeps time and sends vales to store in timer[] occasionally
int timer[10];//storage for timing of events
int slope[10];//storage for slope of events
unsigned int totalTimer;//used to calculate period
unsigned int period;//storage for period of wave
byte index = 0;//current storage index
float frequency;//storage for frequency calculations
int maxSlope = 0;//used to calculate max slope as trigger point
int newSlope;//storage for incoming slope data
int slopeTol = 20;
//variables for decided whether you have a match
byte noMatch = 0;//counts how many non-matches you've received to reset variables if it's been too long byte slopeTol = 3;//slope tolerance- adjust this if you need
int timerTol = 10;//timer tolerance- adjust this if you need
//variables for amp detection
unsigned int ampTimer = 0;
byte maxAmp = 0;
byte checkMaxAmp;
byte ampThreshold = 30;//raise if you have a very noisy signal
#include <Stepper.h>
#define STEPS 200
Stepper stepper(STEPS, 8, 9, 10, 11);


const byte motorPin1 = 8;
const byte motorPin2 = 9;
const byte motorPin3 = 10;
const byte motorPin4 = 11;


int freq = 1000;
void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT); //led indicator pin
  pinMode(12, OUTPUT); //output pin
  stepper.setSpeed(5);
  cli();//diable interrupts
  //set up continuous sampling of analog pin 0 at 38.5kHz
  //clear ADCSRA and ADCSRB registers
  ADCSRA = 0;
  ADCSRB = 0;
  ADMUX |= (1 << REFS0); //set reference voltage
  ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
  ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz
  ADCSRA |= (1 << ADATE); //enabble auto trigger
  ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
  ADCSRA |= (1 << ADEN); //enable ADC
  ADCSRA |= (1 << ADSC); //start ADC measurements
  sei();//enable interrupts
}


ISR(ADC_vect)  //when new ADC value ready
{
  PORTB &= B11101111;//set pin 12 low
  prevData = newData;//store previous value
  newData = ADCH;//get value from A0
  if (prevData < 127 && newData >= 127) //if increasing and crossing midpoint
  {
    newSlope = newData - prevData;//calculate slope
    if (abs(newSlope - maxSlope) < slopeTol) //if slopes are ==
    {
      //record new data and reset time
      slope[index] = newSlope;
      timer[index] = time;
      time = 0;
      if (index == 0) //new max slope just reset
      {
        PORTB |= B00010000;//set pin 12 high
        noMatch = 0;
        index++;//increment index
      }
      else if (abs(timer[0] - timer[index]) < timerTol && abs(slope[0] - newSlope) < slopeTol) //if timer duration and slopes match
      {
        //sum timer values
        totalTimer = 0;
        for (byte i = 0; i < index; i++)
        {
          totalTimer += timer[i];
        }
        period = totalTimer;//set period
        //reset new zero index values to compare with
        timer[0] = timer[index];
        slope[0] = slope[index];
        index = 1;//set index to 1
        PORTB |= B00010000;//set pin 12 high
        noMatch = 0;
      }
      else //crossing midpoint but not match
      {
        index++;//increment index if (index > 9){
        reset();
      }
    }
  }
  else if (newSlope > maxSlope) //if new slope is much larger than max slope
  {
    maxSlope = newSlope;
    time = 0;//reset clock
    noMatch = 0;
    index = 0;//reset index
  }
  else //slope not steep enough
  {
    noMatch++;//increment no match counter
    if (noMatch > 9)
    {
      reset();
    }
  }


  if (newData == 0 || newData == 1023) //if clipping
  {
    clipping = 1;//currently clipping
    Serial.println("clipping");
  }
  time++;//increment timer at rate of 38.5kHz
  ampTimer++;//increment amplitude timer
  if (abs(127 - ADCH) > maxAmp)
  {
    maxAmp = abs(127 - ADCH);
  }
  if (ampTimer == 1000)
  {
    ampTimer = 0;
    checkMaxAmp = maxAmp;
    maxAmp = 0;
  }
}
void reset() //clean out some variables
{
  index = 0;//reset index
  noMatch = 0;//reset match couner
  maxSlope = 0;//reset slope
}
void checkClipping() //manage clipping indication
{
  if (clipping) //if currently clipping
  {
    clipping = 0;
  }
}


void loop()
{
  checkClipping();
  if (checkMaxAmp > ampThreshold)
  {
    int frequency = 38462 / float(period); //calculate frequency timer rate/period
    if (freq - 10 > frequency)
    {
      for ( int i = 0 ; i < 100 ; i = i + 1)
      {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, HIGH);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, HIGH);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(3);
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, LOW);
        delay(3);
      }
      delay(1000);
    }
    if (freq - 5 > frequency)
    {
      for ( int i = 0 ; i < 50 ; i = i + 1)
      {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, HIGH);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, HIGH);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(3);
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, LOW);
        delay(3);
      }
      delay(6000);
    }
    if (freq + 10 < frequency)
    {
      for ( int i = 0 ; i < 100 ; i = i + 1)
      {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, HIGH);
        delay(3);
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, LOW);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, HIGH);
        delay(3);
      }
      delay(1000);
    }
    if (freq + 5 < frequency)
    {
      for ( int i = 0 ; i < 50 ; i = i + 1)
      {
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, HIGH);
        delay(3);
        digitalWrite(motorPin1, LOW);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, HIGH);
        digitalWrite(motorPin4, LOW);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, HIGH);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, LOW);
        delay(3);
        digitalWrite(motorPin1, HIGH);
        digitalWrite(motorPin2, LOW);
        digitalWrite(motorPin3, LOW);
        digitalWrite(motorPin4, HIGH);
        delay(3);
      }
      delay(6000);
    }
  }
  delay(100);
}

Thank you guys for your response!!
This is the code i found for a guitar tuner.I made the circuit on breadboard but i realised that the code was wrong.
Im a totally beginner on programming and i couldn't expect that this project could be so messy.
Sorry for any inconvenience i may caused,I will try to split this project in parts and repost it.

Your sketch includes the Stepper library and declares a Stepper object but doesn't use it. It seems to drive four 'motor' pins directly. You could replace much of your loop() with a couple of calls to stepper.step().

Thanks a lot!!