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!