Changing the role of the PB2 pin of ATTINY85 from interrupts INT0 to output

Hi,

In ATTINY85 with a limited number of inputs/outputs I need to change input interrupt pin PB2 to output pin (and probably return interrupt pin back). How to make this?
Thanks,
Leo

//...ATTINY85 Arduino IDE (SpenceKonde core) based on Nick Gammon example 

void setup() {
  byte IRsw = 2; //pin 7 connected to IR module output
  pinMode(IRsw, INPUT);
  ADCSRA = 0; // ADC OFF
  MCUCR &= ~(bit(ISC01) | bit(ISC00)); // INT0 on low level: IRsw=2 (pin 7)
  }
ISR(INT0_vect) {
  GIMSK &= ~bit(INT0);     // disable INT0
  }
void loop() {
  power_timer0_enable ();
  time1 = micros(); //take time when PB2/pin7 goes low
  while (digitalRead (IRsw) == LOW) {} //wait as it stays low
  time1 = micros() - time1; // find pulse length
  
  if (time1 > 50000) {
    // here I should change the role of the PB2 - from input to output, HIGH; 
    // direct approach as pinMode(IRsw, OUTPUT) does not work 
    }
 noInterrupts ();
  GIFR  = bit (INTF0);   // clear interrupt flag
  GIMSK = bit (INT0);    // enable INT0
  power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
  set_sleep_mode (SLEEP_MODE_PWR_DOWN);
  sleep_enable ();       // ready to sleep
  interrupts ();
  sleep_cpu ();          // sleep
}

No pin is an interrupt pin till you make it one with attachInterrupt().

I need to change input interrupt pin PB2 to output pin

Why not just pinMode(IRsw, OUTPUT)?

void setup() {
  byte IRsw = 2; //pin 7 connected to IR module output

Since the IRsw variable is declared in setup() it is only in scope in setup(). It will not exist outside of setup(). Usually pins are made global scope.

Thank you for a reply. pinMode(IRsw, OUTPUT) I indeed used (see comments in #1) but without success. Did I understand you correct that when pin is declared within Setup this approach should work? Asking this as I probably declared it globally by mistake...

Yes, pinMode(IRsw, OUTPUT) works... thanks