Hello there,

I am a newbie with Arduino. I have hooked up a ST7920-based GLCD display with an Arduino Uno. I can display the first page OK. I want to display the next page when a pushbutton (SW1), connected to D11, is momentarily pressed. I cannot use any interrupt pin as both the interrupt pins (D2 and D3) have been used.

Can anyone tell me how to do this?

My code is as below:

Code:
#include "U8glib.h"
#include "max6675.h"

U8GLIB_ST7920_128X64_1X u8g(7, 6, 5 ,8); //Enable, RW, RS, RESET

// Used for generating interrupts using CLK1 signal
  const int CLK1 = 2;
  
  // Used for reading DT1 signal
  const int DT1 = 9;

  // Used for generating interrupts using CLK2 signal
  const int CLK2 = 3;
  
  // Used for reading DT1 signal
  const int DT2 = 10;
  
  // Used for the push button switches
  const int PinSW1 = 11;
  const int PinSW2 = 12;
  
  // Keep track of last rotary value
  int lastCount1 = 50;
  int lastCount2 = 50;// this is the temp in Centigrade
  int lastCount3;// this holds the temp in Fahrenheit
  int curr_temp;// This is the current temperature
  
  // Updated by the ISR (Interrupt Service Routine)
  volatile int virtualPosition1 = 500;
  volatile int virtualPosition2 = 500;

char tmp_string1[8];
char tmp_string2[8];//Centigrade
char tmp_string3[8];//fahrenheit
char tmp_string4[8];// current temperature (C);

bool tempFlag = false;// to display "C"

int ktcSO = A5;
int ktcCS = A4;
int ktcCLK = A3;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

void setup() {  
  
  u8g.setFont(u8g_font_7x14B);
  u8g.setColorIndex(1); // Instructs the display to draw with a pixel on.

  // Rotary pulses are INPUTs
    pinMode(CLK1, INPUT);
    pinMode(DT1, INPUT);
    pinMode(PinSW1, INPUT);
    pinMode(PinSW2, INPUT);

    pinMode(CLK2, INPUT);
    pinMode(DT2, INPUT);
  
    // Switch is floating so use the in-built PULLUP so we don't need a resistor
    //pinMode(PinSW, INPUT_PULLUP);
  
    // Attach the routine to service the interrupts
    attachInterrupt(digitalPinToInterrupt(CLK1), isr1, LOW);
attachInterrupt(digitalPinToInterrupt(CLK2), isr2, LOW);

}

void loop() { 

    if ((!digitalRead(PinSW2)) && (tempFlag == false))
    {
    tempFlag = true;
    }

    else if ((!digitalRead(PinSW2)) && (tempFlag == true))
    {
      tempFlag = false;
    }
   
 while (!digitalRead(PinSW2));
      delay(10);

 if (virtualPosition1 != lastCount1) {
  
      // Write out to serial monitor the value and direction
      
      // Keep track of this new value
      lastCount1 = virtualPosition1 ;
   }

      if (virtualPosition2 != lastCount2) {
  
      
      // Keep track of this new value
      lastCount2 = virtualPosition2 ;
   }

 u8g.firstPage();
  do {  
    draw();    
  } 
  
  while( u8g.nextPage() ); 
}

void draw(){

  lastCount3 = (((lastCount2 * 9)/5) + 32);
     itoa(lastCount1, tmp_string1, 10); // https://www.avrfreaks.net/forum/how-...ariable-u8glib
     itoa(lastCount2, tmp_string2, 10);
     itoa(lastCount3, tmp_string3, 10);
     
     
  u8g.firstPage(); 
  do {
     u8g.setFont(u8g_font_7x14B);
  u8g.drawStr( 54, 12, "SET");
   u8g.drawStr( 20, 30, "SPEED");
   
   if (tempFlag == false)
   {
    u8g.drawStr( 76, 30, "TEMP(C)");
   }
   else
   {
    u8g.drawStr( 76, 30, "TEMP(F)");
   }
   
  u8g.drawStr(28, 50, tmp_string1);

  if (tempFlag == false)// that is Centigrade
  {
  u8g.drawStr(80, 50, tmp_string2);
  }

   else
   {
    u8g.drawStr(80,50,tmp_string3);// fahrenheit
   }
}
while( u8g.nextPage() );
//delay(10);

while (!digitalRead(PinSW1))
u8g.firstPage();

do
{
draw2();
}
while (u8g.nextPage());
  //delay(5000);
}

void draw2(){
  u8g.drawStr( 50, 12, "CURRENT");
curr_temp = (ktc.readCelsius());
      itoa(curr_temp, tmp_string4, 10);
       u8g.drawStr(60, 60,tmp_string4);// current temperature
 }

  void isr1 ()  {
    static unsigned long lastInterruptTime1 = 0;
    unsigned long interruptTime1 = millis();
  
    // If interrupts come faster than 5ms, assume it's a bounce and ignore
    if (interruptTime1 - lastInterruptTime1 > 5) 
    {
      if (digitalRead(DT1) == LOW)
      {
        virtualPosition1 = virtualPosition1 - 10 ;

         if (virtualPosition1 <=100)

        {
          virtualPosition1 = 100;
        }
      }
      else 
      {
        virtualPosition1 = virtualPosition1 + 10 ;

        if (virtualPosition1 >=1000)

        { 
          virtualPosition1 = 1000;
        }
      }  
    }
    // Keep track of when we were here last (no more than every 5ms)
    lastInterruptTime1 = interruptTime1;
  }

  void isr2 ()
  {
        static unsigned long lastInterruptTime2 = 0;
    unsigned long interruptTime2 = millis();
  
    // If interrupts come faster than 5ms, assume it's a bounce and ignore
    if (interruptTime2 - lastInterruptTime2 > 5) 
    {
      if (digitalRead(DT2) == LOW)
      {
        virtualPosition2 = virtualPosition2 - 10 ;

         if (virtualPosition2 <=100)

        {
          virtualPosition2 = 100;
        }
      }
      else 
      {
        virtualPosition2 = virtualPosition2 + 10 ;

        if (virtualPosition2 >=1000)

        { 
          virtualPosition2 = 1000;
        }
      }  
    }
    // Keep track of when we were here last (no more than every 5ms)
    lastInterruptTime2 = interruptTime2;
  }