[SOLVED] how to display feet,inches on adafruit 0.56" 4 digit 7 seg

hi, I'm using this display with this board and an HC_SR04.
I can display the distance on cm but I don't know how to display the distance in feet, inches.

this is my newbie code:

#include <NewPing.h>

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

#define trigger_Port 7
#define echo_Port 8
//#define max_distance 400

long cm, INCHES, feet, inches;

NewPing sonar(trigger_Port, echo_Port);


void setup() {// put your setup code here, to run once:

matrix.begin(0x70);

matrix.clear();

}

void loop() { // put your main code here, to run repeatedly:
  
durata = sonar.ping_median(10);

  cm = ((durata/2) / 29.1);
  INCHES = ((durata/2) / 74); 
  feet = INCHES / 12;
  inches = INCHES% 12; //es x = 7% 5; // X ora contiene 2
    

matrix.print(cm);

matrix.writeDisplay();


delay(100);
}

some tips?

How are you intending to format feet and inches on a 4 digit display ? With 2 digits for the feet and 2 digits for the inches with a colon (':') as separator ?
You appear to have done the calculation of feet and inches already.

thanks for answering, yes, two digit for feet and two digit for inches with a dot to separate (ex. 10.11)

you can try adding something like this after calculating feet and inches:

int impDisplay =  feet*100 + inches ;  // imperial units
matrix.print( impDisplay , DEC ) ;
matrix.drawColon( true ) ;

and comment out matrix.print(cm);

with your solution the display say feet:inches (ex. 9:11) and not feet.inches (ex. 9.11)

Surely you will want to add a few bushels and furlongs to your display.

The civilised world uses a period or comma to indicate decimal point.

I suggest that you invent some other "separator" to distinguish your unusual measurement system.

David.

david_prentice:
Surely you will want to add a few bushels and furlongs to your display.
. . .

I did wonder why he did not also ask for yards to be included. The example would then be (ex. 3.0.11)
that is three yards, no feet and 11 inches. With some 7 segment displays, it would even be possible.

cepics:
with your solution the display say feet:inches (ex. 9:11) and not feet.inches (ex. 9.11)

I can't immediately see in the library how to address the individual decimal points, but maybe try this:

replace:

matrix.drawColon( true ) ;

with:

matrix.writeDigitNum( 1 , feet%10 , true ) ;

to add a decimal point to digit 1 (counting from 0 )

cooooooool it works!!!!!

thanks a lot :slight_smile: :slight_smile: :slight_smile: