Pages: [1]   Go Down
Author Topic: Encoder code stops perfect one way, not the other?  (Read 13 times)
0 Members and 4 Guests are viewing this topic.
Offline Offline
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using an Encoder to set a Temperature in a climate control system for my old jeep. To eliminate the vacuum lines all together.

What i want to do is to have a set temperature between 50*F and 100*F  for the air temp blowing out. The full automatic will come later.  I also wanted to turn the knob clockwise until 99 then display "Hot"  and no matter how many times the knob is turned clockwise it will only require one "click" (detent) counterclockwise to go down from "Hot" to 99* so far using the Encoder.h library from I have managed to do that.

However the problem comes when i want to set the low temp. Turning CC (counterclockwise) it counts down to 51*F then on the next click displays "Max" exactly how it should. HOWEVER, thats it. No matter how many times i turn the knob it will not display anything other than "Max" I'm completely stumped.

Here's the part of my Code that i'm concerned with.

#include "Encoder.h"
Encoder tempKnob (3,4);

//other inputs or variables                                                 
int oldTemp =-999;                                   //placeholder for temp value
byte T = 0;

void loop() {
  //Temperature encoder read
  int newTemp =;
   if (newTemp != oldTemp) {
     oldTemp = newTemp;
  // oled display
  do {
  } while( u8g.nextPage() );

void draw(void) {
  // graphic commands to redraw the complete screen should be placed here 
  u8g.setFont(u8g_font_gdr11r);       //font set Gentium size 25 r= 1 - 127 only
  u8g.drawStr( 5, 14, "Manual");      //set location for mode display
  u8g.setFont(u8g_font_gdr25r);       //font set Gentium size 25 r=1-127 only
  u8g.setPrintPos (0,45);             //set location for temp display
  if (T >= 100) {                     //condition for max heat
     u8g.print("Hot");                //display hot
     tempKnob.write(400);             //write encoder to 400 gets divided by 4 in byte "T"
  if (T <= 50) {                      //condistion for max cool
     u8g.print ("Max");               //display max
     tempKnob.write (200);            //write encoder to 200 gets divided by 4 in byte "t"
  else if ((T > 50) && (T < 100)) {   //condition to display number for temp
    if (T < 100) {                    //if only 2 digits
      u8g.print("  ");                //space to the right
    u8g.print(T);                     //display set temp
    u8g.drawCircle(60, 23, 3);        //circle representing degree


So far i have tried;
Changing  the "if" to "else if"
Changing the tempKnob.write () to all sorts of variables above and below 200
Changing the "<=" to less "<" only. and even "=="

I'm sure its something simple that i'm missing. But i can't for the life of me figure it out.

Thank you!

Pages: [1]   Go Up
Jump to: