long distanza=0;

long tempo=0;

const float c=0.017;

char y=’0′;

 

 

void setup()

{

for(int i=7; i<=13; i++){

pinMode(i, OUTPUT);

}

 

pinMode(6, OUTPUT); //trig

pinMode(5, INPUT);  //echo

 

Serial.begin(9600);

}

 

void loop()

{

digitalWrite(6, LOW);

digitalWrite(6, HIGH);

delayMicroseconds(10);

digitalWrite(6, LOW);

tempo=pulseIn(5, HIGH);

distanza=tempo*c;

 

if(distanza<50){

if(y!=’0′){

y=’0′;

Serial.println(“0-49”);

}

}

if(distanza>=50 && distanza<100){

if(y!=’1′){

y=’1′;

Serial.println(“50-99”);

}

}

 

 

  if(distanza>=100 && distanza<150){

if(y!=’2′){

y=’2′;

Serial.println(“100-149”);

}

}

if(distanza>=150 && distanza<200){

if(y!=’3′){

y=’3′;

Serial.println(“150-199”);

}

}

if(distanza>=200 && distanza<250){

if(y!=’4′){

y=’4′;

Serial.println(“200-249”);

}

}

if(distanza>=250 && distanza<300){

if(y!=’5′){

y=’5′;

Serial.println(“250-299”);

}

}

if(distanza>=300){

if(y!=’6′){

y=’6′;

Serial.println(“300+”);

}

}

number(y);

}

 

void number(char num)

{

char x=num;

switch(x)

{

case ‘0’:

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

digitalWrite(9, HIGH);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, HIGH);

digitalWrite(13, LOW);

break;

 

 

    case ‘1’:

digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

digitalWrite(13, LOW);

break;

 

case ‘2’:

digitalWrite(7, LOW);

digitalWrite(8, HIGH);

digitalWrite(9, HIGH);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, LOW);

digitalWrite(13, HIGH);

break;

 

case ‘3’:

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, LOW);

digitalWrite(13, HIGH);

break;

 

case ‘4’:

digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

digitalWrite(11, LOW);

digitalWrite(12, HIGH);

digitalWrite(13, HIGH);

break;

 

case ‘5’:

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

digitalWrite(9, LOW);

digitalWrite(10, LOW);

digitalWrite(11, HIGH);

digitalWrite(12, HIGH);

digitalWrite(13, HIGH);

break;

 

    case ‘6’:

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

digitalWrite(9, HIGH);

digitalWrite(10, LOW);

digitalWrite(11, HIGH);

digitalWrite(12, HIGH);

digitalWrite(13, HIGH);

break;

 

case ‘7’:

digitalWrite(7, HIGH);

digitalWrite(8, LOW);

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, LOW);

digitalWrite(13, LOW);

break;

 

case ‘8’:

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

digitalWrite(9, HIGH);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, HIGH);

digitalWrite(13, HIGH);

break;

 

case ‘9’:

digitalWrite(7, HIGH);

digitalWrite(8, HIGH);

digitalWrite(9, LOW);

digitalWrite(10, HIGH);

digitalWrite(11, HIGH);

digitalWrite(12, HIGH);

digitalWrite(13, HIGH);

break;

}

}