Complete newbie here!

I am trying to allocate different digits on my seven segment display to pair (feet) and (Inches) with my ultrasonic sensor. Basically what I am trying to do here is to use the 0x00 and 0x00 for feet and 0x05 and 0x06 for my inches. For some reasons it seems like the way I am coding everything does not work out. Any clues?

Thanks a lot!

```
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_7segment matrix = Adafruit_7segment();
uint8_t counter = 0;
void setup() {
#ifndef __AVR_ATtiny85__
Serial.begin(9600);
Serial.println("V1.08");
#endif
matrix.begin(0x70);
matrix.print(1.08);
matrix.writeDisplay();
delay(2000);
matrix.clear();
int n = 1;
int trig = 3; // attach pin 3 to Trig
int echo = 4; //attach pin 4 to Echo
}
void loop() {
const int trigPin = 3;
const int echoPin = 4;
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm, feet, boolinches;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(25);
digitalWrite(trigPin, HIGH);
delayMicroseconds(25);
digitalWrite(trigPin, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
boolinches = microsecondsToBoolinches(duration);
cm = microsecondsToCentimeters(duration);
inches = microsecondsToInches(duration);
feet = microsecondsToFeet(duration);
//write distance
if (feet >= 20)
matrix.writeDigitNum(0x00, 9999);
else
{
matrix.writeDigitNum(0x00,feet);
matrix.writeDisplay();
matrix.writeDigitNum(0x05,boolinches);
matrix.writeDisplay();
delay(10);
}
if (feet >= 20)
Serial.print("OVER DISTANCE");
else
{
Serial.print(feet);
Serial.print("'");
Serial.print(boolinches);
Serial.print(" '' ");
Serial.println("");
}
matrix.clear();
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 73.746 / 2;
}
long microsecondsToBoolinches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return ((((microseconds / 29 / 2)*50)/127)%12);;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}
long microsecondsToFeet(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 884.952 / 2;
}
```