Code impriment: ino / cpp / h

I wrote a sketch to manage a recording from anemometer.
Now I would like to improve deeply the sketch and gain a good organization.
I know we can keep the main structure and include several external parts with .cpp et .h

Is there someone to show me how can I do ?

This is my sketch

Anemometer___RTC.ino (4.72 KB)

const byte LED = 7;
float varCompteur = 0, period, freq, vwind, vmax, duree, vint, vmoy;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int count, Beaufort, delay_min;
bool b_rafale;
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#define DS1307_I2C_ADDRESS 0x68
const int chipSelect = 10;
volatile int top;
String File_record = "Test01";


void pinChange ()
{
  count = count+1;
  
  digitalWrite (LED, HIGH);

  period = varCompteur * 16 * 256 / 1000; 
    Serial.print(period,3); Serial.print(" / ");
    Serial.println(varCompteur,3);
  period = max ( delay_min , period ) ;  
  if (period == delay_min) {return;} 
   
  freq = 1000 / period; 
    
  duree = duree + period; 
    
  vwind = freq * 2.4;
    
  vint = vint + (vwind * period); 
    
  if (count < 3 ) { vmoy = 0;} else {vmoy = ( vint / duree ) ;}
    
  if (count < 10) { vmax = 0;} else {if (vwind > vmax) { vmax = vwind ;} else { vmax = vmax ;}}
  
  if ((vwind > (3 * vmoy)) && (count > 10) ) {b_rafale = 1;} 

      if ((vwind < 1)) {Beaufort = 0;} else 
      if ((vwind > 1) && (vwind < 5)) {Beaufort = 1;} else
      if ((vwind > 6) && (vwind < 11)) {Beaufort = 2;} else
      if ((vwind > 12) && (vwind < 19)) {Beaufort = 3;} else
      if ((vwind > 20) && (vwind < 28)) {Beaufort = 4;} else
      if ((vwind > 29) && (vwind < 38)) {Beaufort = 5;} else
      if ((vwind > 39) && (vwind < 49)) {Beaufort = 6;} else
      if ((vwind > 50) && (vwind < 61)) {Beaufort = 7;} else
      if ((vwind > 62) && (vwind < 74)) {Beaufort = 8;} else
      if ((vwind > 75) && (vwind < 88)) {Beaufort = 9;} else
      if ((vwind > 89) && (vwind < 102)) {Beaufort = 10;} 

    varCompteur = 0;
    digitalWrite (LED, LOW);


}  

void Flash_RTC ()
{
  digitalWrite(6,HIGH);
  top = top + 1;
  delay(200);
  digitalWrite(6,LOW);
  Serial.println(top);
}












void setup ()
{
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {Serial.println("Card failed, or not present");return;}
  
  Serial.println("card initialized.");
  
  File dataFile = SD.open(File_record, FILE_WRITE); 
    if (dataFile) { dataFile.println("Date ; Heure ; Period ; Freq ; Speed ; Max Speed ; Average speed ; Rafale ; Beaufort"); dataFile.close();}  
    
  pinMode (LED, OUTPUT);  // so we can update the LED
  
  attachInterrupt (0, pinChange, RISING); // Anemometer
  
  bitClear (TCCR2A, WGM20); // WGM20 = 0
  bitClear (TCCR2A, WGM21); // WGM21 = 0 
  TCCR2B = 0b00000110;      // Clock / 256 soit 16 micro-s et WGM22 = 0
  TIFR2 = 0b00000001;       // TOV2
  
  pinMode(7,OUTPUT);  digitalWrite(7,LOW); pinMode(6,OUTPUT); digitalWrite(6,LOW);

  Wire.begin();
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0x07);
  Wire.write(0x10);
  Wire.endTransmission();
  attachInterrupt(1, Flash_RTC , RISING); // SQW RTC
} 








































byte bcdToDec(byte val) 
{ return ( (val/16*10) + (val%16) );}

void getDateDs1307(byte *second,byte *minute,byte *hour,byte *dayOfWeek,byte *dayOfMonth,byte *month,byte *year) //---
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.write(0);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  *second     = bcdToDec(Wire.read() & 0x7f);
  *minute     = bcdToDec(Wire.read());
  *hour       = bcdToDec(Wire.read() & 0x3f);  // Need to change this if 12 hour am/pm
  *dayOfWeek  = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month      = bcdToDec(Wire.read());
  *year       = bcdToDec(Wire.read());
}























void loop ()
{ 
  if (bitRead (TIFR2, 0) == 1) {bitSet (TIFR2, TOV2);varCompteur++;}

  if ( top == 60 )
  {
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);

  File dataFile = SD.open(File_record, FILE_WRITE); 
    if (dataFile) {dataFile.print(dayOfMonth);dataFile.print("/");dataFile.print(month);dataFile.print("/");dataFile.print(year);dataFile.print(" ; ");
                   dataFile.print(hour);dataFile.print(":");dataFile.print(minute);dataFile.print(":");dataFile.print(second);dataFile.print(" ; ");
                   dataFile.print(period);dataFile.print(" ; ");
                   dataFile.print(freq,1);dataFile.print(" ; ");
                   dataFile.print(vwind,1);dataFile.print(" ; ");
                   dataFile.print(vmax,1);dataFile.print(" ; ");   
                   dataFile.print(vmoy,1);dataFile.print(" ; ");
                   dataFile.print(b_rafale);dataFile.print(" ; ");
                   dataFile.println(Beaufort);
                   dataFile.close();
                   count = 0;
                   vint = 0;    
                   b_rafale = 0;          
                   }              
  top = 0 ;
  }
}

"varCompteur" - you're counting discrete events - why use a floating-point variable?

Probable a mistake.
You are right an integer is so appropriate