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);
}
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.
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.