Audio Preamp Remote Control and Display

Hi I wonder if someone can assist me finalizing my code?

I am using an Arduino Uno to control an Audio Preamp and have so far manged to achieve most of the control but am having difficulty in displaying larger text on a second screen when the remote is pressed.
Currently I have connected a potentiometer on one of the analogue pins and an encoder on another two pins for testing purposes.
What I want to happen is when manually controlling the preamp as the display shows Volume and the Input will be shown, but when far away all I want is the display to show just the Input number in larger text.
In the second photo you can see I have nearly achieved it but all it appears to be doing is taking the selection of code from lines 67 to 77 and ignoring the code in lines 87 to 90 but it is changing the font size. Any help would be appreciated.

#include <U8glib.h>
 #include <RotaryEncoder.h>
 #include <Wire.h>
U8GLIB_SSD1306_128X64 u8g(13, 11, 10, 9, 8);  // D0=13, D1=11, CS=10, DC=9, Reset=8
int encoderPosCount2;
int sensorPin = A0;
int sensorValue;
int val = 0;
int sensorValue1;
RotaryEncoder encoder(A2, A3);
int remotepin = 2;
int remotepinstate = 0;
const int ledPin =  13; 


void setup() {  
  u8g.setFont(u8g_font_unifont);
  u8g.setColorIndex(1); // Instructs the display to draw with a pixel on.
   Serial.begin(9600);
 
    Wire.begin(); // join i2c bus (address optional for master)
pinMode(2,INPUT);
pinMode(ledPin, OUTPUT);

byte val = 0;
}

  
void loop() {

u8g.firstPage(); 
remotecontrol(); 
    do {  
    draw1(); 
   draw2();
    
   if (remotepinstate == 1) {draw2();
 u8g.setFont(u8g_font_fub49n);
}
else {draw1();

    u8g.setFont(u8g_font_unifont);
}
  }  while( u8g.nextPage() ); 
 
 
  static int pos = 0;
  encoder.tick();

  int newPos = encoder.getPosition();
  if (pos != newPos) {
    sensorValue = analogRead(A0); 
      encoderPosCount2 = constrain(newPos, 0, 255);
    pos = newPos;
     
  }
  //next piece of code controls the digital pot
   Wire.beginTransmission(44); // transmit to device #44 (0x2c)
  // device address is specified in datasheet
  Wire.write(byte(0x00));            // sends instruction byte
  Wire.write(encoderPosCount2);             // sends potentiometer value byte
  Wire.endTransmission();     // stop transmitting  

}
void draw1(){
    
  u8g.drawStr( 30, 10, "Willow II");
  u8g.drawStr( 0, 30, "Volume");
 u8g.drawStr( 0, 55, "Input");
 sensorValue = analogRead(A0);
enum {BufSize=5}; // If a is short use a smaller number, eg 5 or 6 
char buf[BufSize];
char buf1[BufSize];
snprintf (buf, BufSize, "%d", encoderPosCount2);
snprintf (buf1, BufSize, "%d", sensorValue);
u8g.drawStr(65, 30, buf);
u8g.drawStr(65, 55, buf1);
 
}

void remotecontrol() {
 remotepinstate = digitalRead(remotepin);

}
void draw2(){ 

enum {BufSize=5}; // If a is short use a smaller number, eg 5 or 6
char buf1[BufSize]; 
snprintf (buf1, BufSize, "%d", sensorValue);//this is the only way to display a value!
u8g.drawStr(65, 55, buf1);

}

Are you running the OLED without a connection to VCC, or is that an optical illusion?

Optical illusion there is a wire underneath that is not visible.

enum {BufSize=5}; // If a is short use a smaller number, eg 5 or 6

Why is this a local variable? Why is it an enum?

snprintf (buf1, BufSize, "%d", sensorValue);//this is the only way to display a value!

In a 5 character array, write a value that could potentially be 6 characters plus the terminating NULL. Hmmm...

(-32768 is 6 characters)

char buf[BufSize];
char buf1[BufSize];
snprintf (buf, BufSize, "%d", encoderPosCount2);
snprintf (buf1, BufSize, "%d", sensorValue);
u8g.drawStr(65, 30, buf);
u8g.drawStr(65, 55, buf1);

If your house is on fire, and the bucket brigade shows up to put it out, wouldn't you prefer that they reuse the buckets? Fill a bucket. Pour it on the fire. Set the bucket aside. Fill another bucket. Pour it on the fire. Can you see how to re-arrange this code and reuse the bucket?

    do { 
    draw1();
   draw2();
   
   if (remotepinstate == 1) {draw2();
 u8g.setFont(u8g_font_fub49n);
}
else {draw1();

    u8g.setFont(u8g_font_unifont);
}
  }  while( u8g.nextPage() );

Perhaps it's the shitty formatting, and perhaps it's just me, but drawing the text and THEN defining what size font to use seems ass-backwards.

This is my first project and learning the Arduino language so please take it easy on me.

I have copy pasted a lot of the code to get to this point , some of it I understand a lot I do not.

This line of code I do not understand it one bit but it allowed me to display a variable.

snprintf (buf1, BufSize, "%d", sensorValue);//this is the only way to display a value!

Again I just copy pasted what was on a tutorial I read and it worked.

So what would you recommend so that the variable shows up on another screen but with increased font size?

The point here is when you are 15 feet away from this OLED display all I want to see is the variable ie volume number but since it will be seen for only a few seconds the same will be true of the input it will be just text in the final code saying Tape,Tuner Phono etc.

The rest of the program works well and the Wire loop does indeed increment and decrements the volume on the digital pot.

You could be right about the shitty formatting but how then do I get the Draw2 loop to change the font size of the variable declared in the loop to increase in size but not the previous screen text and numbers?

So what would you recommend so that the variable shows up on another screen but with increased font size?

That function simply converts an int (the 4th argument) to a string, storing the string in the 1st argument, with a length limited by the 2nd argument, using the format defined by the 3rd argument.

Suppose I told you to:
Stencil "This is some text" on the wall.
Use the 4 inch high letter stencil.

Suppose you can only read and remember one instruction at a time. What would you do, considering that you are holding the 1 inch high letter stencil in your hand?

Now, suppose I said:
Use the 4 inch high letter stencil.
Stencil "This is some text" on the wall.

Would the result be the same? I don't think so.

Thank you so much!!

At first I could not understand your cryptic comment and was about to dismiss it but on reading over and over again the light bulb went on.

As a newbie to this programming sometimes it takes a little nudge to see things a different way and it certainly has again thank you for responding.

Great Forum.