#include <RotaryDial.h>

#define ROTARY_DIAL_PULSE_PIN 2 //PIN 2 supports interrupts on Arduino Nano
#define ROTARY_DIAL_TIMEOUT 3000 //If no numbers are dialed for this period, newline is sent

float i;

void setup() {
  Serial.begin(9600);
  RotaryDial::setup(ROTARY_DIAL_PULSE_PIN);
}

unsigned long lastdigit = 0;
int newline = true;

void loop() {
  if(RotaryDial::available()) {
    i = RotaryDial::read();
    lastdigit = millis();
    newline = false;
    umwan();
  } 
  else {
    if(!newline && millis() - lastdigit > ROTARY_DIAL_TIMEOUT) {
      Serial.println(" OK");
      newline = true;
    }
  }

  
}


void umwan(){
  if(i == 1){
    i = 1;
  }
  else{
    if(i == 10){
      i = 2;
    }
    else{
      if(i == 11){
        i = 3;
      }
      else{
        if(i == 13){
          i = 4;
        }
        else{
          if(i == 14){
            i = 5;
          }
          else{
            if(i == 15){
              i = 6;
            }
            else{
              if(i == 16){
                i = 7;
              }
              else{
                if(i == 17){
                  i = 8;
                }
                else{
                  if(i == 18){
                    i = 9;
                  }
                  else{
                    if(i == 19){
                      i = 0;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

Serial.println(i);
}