RESET button used as a user button

With this topic, I want to share an idea that is working fine:
Using the RESET button as if it is a normal user button.

Background:
On Arduino UNO, Nano and other AVR based boards, the reset is hardware wired to the chip reset. The consequence is that it will ALWAYS Reset the chip. However it is possible to read a register (MCUSR) at code start, to know if the reset is the consequence of the action on the button or if it is Power-UP or Watchdog or Brown-Out (power supply unstable).

Based on that, we can imagine some limited possibilities to use the reset button just as if it was a normal button. For example to show an animation with LED, it’s possible to select 1 pattern on a list, by an action on RESET.

Here is a little demo code

// This code demonstrate how it is possible to use the reset button on Arduino, to select options in user code
// The pricniple: The reset source register, internal to AVR core, is read at code start. If reset comes from Power-UP, the RAM byte "reset_idx" is reset
// After each external reset (=button), reset_idx is incremented
// Note: we use RAM, it's value is not lost while the power is ON, if we tell the compiler to not clear it at code startup, we can read the same value as before reset.
// Look at the LED on pin 13...

byte reset_idx  __attribute__ ((section (".noinit"))); // do not clear this RAM at startup
void setup() {
  Serial.begin(57600);
 if (MCUSR & 0x02){ Serial.println("reset source bit1: External Reset Flag");reset_idx++;} // increment at each action on RESET button
 if (MCUSR & 0x04){ Serial.println("reset source bit2: Brown-out Reset Flag");reset_idx+=10;}
 if (MCUSR & 0x08){ Serial.println("reset source bit3: Watchdog System Reset Flag\n");reset_idx+=20;}
 if (MCUSR & 0x01){ Serial.println("reset source bit0: Power-on Reset Flag"); reset_idx=1;} // after power-ON, reset this option to value 1
 MCUSR=0;
 Serial.print("Reset index ");Serial.println(reset_idx); 
 pinMode(13,OUTPUT);// onboard led
}

void loop() {
  // blink: 1 flash after power-UP, and 1 more flash after each action on reset button
  for(byte i=0;i<reset_idx;i++){
    digitalWrite(13,1);
    delay (80);
    digitalWrite(13,0);
    delay (80);  
  }
  delay (1000); 
}

I hope it will be useful to others…
Enjoy
B.

The starting value of the 'noinit' variable is undefined (just like the name suggests),
so this seems very hard to use.

What use can incrementing of an unknown value have?

I was under the impression that when the external reset was disabled through the RSTDISBL fuse that you could use the reset pin as a (almost) normal IO pin on PORT C6. Wouldn't that be much easier? If you're just looking for a free button.

If you use the RSTDISBL fuse, you cannot reprogram the chip anymore without a high voltage (12V) chip erase to have a working reset pin again.

RESET/PCINT14 – Port C, Bit 6

RESET, Reset pin: When the RSTDISBL Fuse is programmed, this pin functions as a normal I/O pin, and the part will have to rely on Power-on Reset and Brown-out Reset as its reset sources. When the RSTDISBL Fuse is unprogrammed,the reset circuitry is connected to the pin, and the pin can not be used as an I/O pin.

If PC6 is used as a reset pin, DDC6, PORTC6 and PINC6 will all read 0.