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
}