#include <EEPROM-Storage.h>
#include "SevenSegmentTM1637.h"
#include "SevenSegmentExtended.h"
//#include "SevenSegmentFun.h"
#define CLK 2//pins definitions for TM1637 and can be changed to other ports       
#define DIO 3
//SevenSegmentTM1637    display(CLK, DIO);
SevenSegmentExtended    display(CLK, DIO);
int swgu = 6;  // switch up is at pin 6
int swgd = 7;   // switch down is at pin 7
int stga = 5;   // switch start turn pin 5

int giri = 10;  // make a variable called giri

//int setgiri; // make a variable called setgiri 
#include <Bonezegei_DRV8825.h>

#define FORWARD 1
#define REVERSE 0

#define PIN_DIR  11
#define PIN_STEP 12



Bonezegei_DRV8825 stepper(PIN_DIR, PIN_STEP);

void setup() {

 

  stepper.begin();
  
  //Speed microseconds per step
  stepper.setSpeed(1000); 
  
 display.begin();            // initializes the display
  display.setBacklight(100);  // set the brightness to 100 %
  
  
  display.print("CIAO");     // display INIT on the display
  delay(1000); 
  display.clear ();               // wait 1000 ms
 EEPROM.write (1,giri);
 EEPROM.read (1); // make the eeprom or atmega328 memory address 1
 pinMode (swgu, INPUT);
 pinMode (swgd, INPUT);
 pinMode (stga, INPUT);
 int i;
 
 // Create array that turns all segments on:
//const uint8_t data[] = {0xff, 0xff, 0xff, 0xff};
//delayMicroseconds(1000);
int giri = EEPROM.read(1); // read the settemp on the eeprom
// Create array that turns all segments off:
//const uint8_t blank[] = {0x00, 0x00, 0x00, 0x00};

}

void loop() {
  // put your main code here, to run repeatedly:
  int i;
 

 //delay (250); // wait for the lcd to refresh every 250 milliseconds
 if             // if we se the switch up pin reading on 1 or 5 volts
     (digitalRead (swgu) == 1 )
   {
     giri ++;  // add one to the settemp, the settemp is the ideal temperature for you
       if(giri > 20) giri = 1;
       display.clear ();
       
         Pul();
   }
   else{}
   EEPROM.write (1,giri);
  if             // if we se the switch up pin reading on 1 or 5 volts
     (digitalRead (swgd) == 1 )
   {
     giri --;  // add one to the settemp, the settemp is the ideal temperature for you
      if(giri < 1) giri = 20;
       display.clear ();
         Pul();
   } 
   else{}
   EEPROM.write (1,giri);

//display.print(giri);



display.printDualCounter(giri, i);

if(digitalRead(stga)==HIGH){

  Motore();
}}

void Motore() {
  for (int i=0; i < giri; i++){
stepper.step(FORWARD, 800);
display.printDualCounter(giri, i+1);}

  delay(1000);
 // stepper.step(REVERSE, giri*200);
  //delay(1000);
 while(1){ // equivale alla funzione loop()
    
   Pul(); }
}

void Pul() {

  if (digitalRead (swgu ) == 1){
  
  Pul();
  }
  else if (digitalRead (swgd ) == 1){
  
  Pul();
  }
  else if (digitalRead (stga ) == 1){
  
  Pul();
  }
   else{
          loop();
   } 
    
  }
 
  

  

4-Digit Display
A4988