LCD to print measuring distance

Hey Guys,

I have a simple measuring wheel project using an Uno, a quadrature encoder and an 8x2 lcd.

I have pulse input coming in using an interrupt and converted to inches but I am trying to get a display read to inches and feet.

IE, (15' 3") or (0' 11")

Here is my simple working code to output inches using the variable "distance":

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 4, 5, 6, 7);

 int val; 
 int encoder0PinA = 2;
 int encoder0PinB = 3;
 long encoder0Pos = 0;
 int encoder0PinALast = LOW;
 int n = LOW;
 int resetp = 8;
 long distance = 0;
 

 void setup() {
   attachInterrupt(0, countPulse, CHANGE);
   pinMode (encoder0PinA,INPUT);
   pinMode (encoder0PinB,INPUT);
   pinMode (resetp, INPUT);
   //Serial.begin (9600);
   
  lcd.begin(8, 2);
  lcd.print("Distance");
 } 

 void loop() { 
// Convert pulses into inches    
  distance = encoder0Pos/5.55;
 
 //Clear any trailing zeros
   if(distance < 10000)
                lcd.print("    ");
       
 // Display Output
     lcd.setCursor(0, 1);
     //lcd.print(encoder0Pos);
     lcd.print(distance);
   } 
   
   
 void countPulse(){
 
     encoder0PinALast = n;
     if (digitalRead(resetp) == HIGH){
     encoder0Pos = 0;
   }
 n = digitalRead(encoder0PinA);
   if ((encoder0PinALast == LOW) && (n == HIGH)) {
     if (digitalRead(encoder0PinB) == LOW) {
       encoder0Pos--;
     } else {
       encoder0Pos++;
     }
   }
 }

Thanks in advance!

Did you have a question?

Don

Hey Don,

Yeah, I'm pretty green to this syntax so I'm trying to wing it here.

I figured out how to convert my output pulses to get inches traveled (like my sketch currently does), and I can easily divide by 12 to output feet traveled.

But how the heck can I tell the sketch to format the output to the lcd showing feet and inches on a single line like so: (as I turn the encoder forward)

2' 8"
2' 9"
2' 10"
2' 11"
3' 0"

Hope this is more clear.
Thanks,
Vince

Now you see why the rest of the civilized world uses the metric system.

You mostly have a programming problem not an LCD problem, made somewhat harder by dealing with feet and inches. Look into the term 'modulo'. This will help you deal with the remainder (the inches) after you have dealt with the quotient (the feet).

Do you want those values displayed one on top of the other so you only see the latest value or do you want them strung out one after the other?

Don

Now you see why the rest of the civilized world uses the metric system.

I fixed that for you.

  distance = encoder0Pos/5.55;

Where does the 5.55 come from?

Also, I see that you are converting from a "long" to a "float" and then back to a "long". Why is this?

Also, what do you want it to do for negative distances? (i.e. rolling the wheel backward past zero)