So I have code that is giving me a result when rotary encoder is turned.
#include <LCD5110_Graph.h>
#include <ClickEncoder.h>
#include <TimerOne.h>
LCD5110 lcd(8,9,10,12,11);
extern unsigned char SmallFont[];
extern unsigned char TinyFont[];
ClickEncoder *encoder;
int16_t last, value = 11968;
void timerIsr() {
encoder->service();
}
void setup() {
Serial.begin(9600);
lcd.InitLCD();
lcd.setFont(SmallFont);
lcd.print("Altimeter",CENTER,15);
lcd.update();
delay(2000);
lcd.setFont(SmallFont);
encoder = new ClickEncoder(A1, A0, A2);
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);
last = -1;
}
void loop() {
int q;
lcd.setFont(SmallFont);
char qnh[3];
value += encoder->getValue();
if (value != last) {
last = value;
q = (value/4);
Serial.print("QNH: ");
Serial.println(q);
lcd.clrScr();
lcd.print("QNH: ",LEFT,0);
dtostrf(q, 3, 0, qnh);
lcd.print(qnh,LEFT+45,0);
lcd.update();
}
}
Result 2992. I need 29.92
However if I change
q = (value/4);
to "value/4*0.01" or "value/4/100" I get:
29 and no decimals