user24470: I am trying to make a circuit using an ATmega328, that has a reset button that behaves like many consumer devices:

A short press just restarts the micro-controller
A long press (5 seconds?) causes the settings to be restored to default

What is the best way to achieve this behaviour? I imagine it is going to require two pins? Can it be done just using passive components?
Thanks!

user31693: You can set the RSTDISBL (bit 7 on the HIGH fuse) to disable the external reset and use the reset pin as PC6 to manage the reset behavior from your program.

The second part is to capture when reset button is pressed: put some code in the ISR for PCINT1 handler when the pin changes (PCINT14 pin function). If you are programming an Arduino board, the reset button is pulled up (press becomes LOW and release becomes HIGH).
Detecting long press or short press is a timer affair. According to your requirements, you will restore some EEPROM values or external state to factory defaults before the microcontroller resets with a long press.
This C snippet will reset the microcontroller after the short or long press (watchdog timer feature):
#include <avr/wdt.h>

    // ...
    wdt_enable(WDTO_15MS);
    for (;;) {}


user4143: It can be done with one button, one resistor, one capacitor and one GPIO pin (in addition to the RESET pin):

simulate this circuit – Schematic created using CircuitLab
Pressing the button causes a LOW pulse on the RESET pin (in the exact same way as the USB interface does).
During your startup procedure you read the GPIO pin you have chosen. If it's LOW the button is still being pressed in. If it's HIGH it has been released.
If you are using an Arduino with the normal bootloader the bootloader itself imposes a 2 second delay (which may be enough for you). Alternatively you will need to have your own delay in your program before reading the button to ensure that you have plenty of time to release the button so you don't accidentally reset your settings.

24470: <p>I am trying to make a circuit using an ATmega328, that has a reset button that behaves like many consumer devices:</p>

<ol>
<li>A short press just restarts the micro-controller</li>
<li>A long press (5 seconds?) causes the settings to be restored to default</li>
</ol>

<p>What is the best way to achieve this behaviour? I imagine it is going to require two pins? Can it be done just using passive components?</p>

<p>Thanks!</p>
 31693: <p>You can set the <strong><em>RSTDISBL</em></strong> (bit 7 on the <em>HIGH fuse</em>) to disable the external reset and use the <em>reset</em> pin as PC6 to manage the reset behavior from your program.</p>

<p><a href="https://i.stack.imgur.com/0PyFw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0PyFw.png" alt="RSTDISBL ATmega328P"></a></p>

<p>The second part is to capture when reset button is pressed: put some code in the <strong>ISR for PCINT1 handler</strong> when the pin changes (<em>PCINT14</em> pin function). If you are programming an Arduino board, the reset button is pulled up (press becomes LOW and release becomes HIGH).</p>

<p>Detecting long press or short press is a timer affair. According to your requirements, you will restore some EEPROM values or external state to <strong>factory defaults</strong> before the microcontroller resets with a long press.</p>

<p>This C snippet will reset the microcontroller after the short or long press (<a href="http://www.atmel.com/webdoc/AVRLibcReferenceManual/group__avr__watchdog.html" rel="nofollow noreferrer">watchdog timer feature</a>):</p>

<pre class="lang-c prettyprint-override"><code>#include &lt;avr/wdt.h&gt;

    // ...
    wdt_enable(WDTO_15MS);
    for (;;) {}
</code></pre>
 4143: <p>It can be done with one button, one resistor, one capacitor and one GPIO pin (in addition to the RESET pin):</p>



<p><img src="https://i.stack.imgur.com/NskfD.png" alt="schematic"></p>



<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fNskfD.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="noreferrer">CircuitLab</a></sup></p>

<p>Pressing the button causes a LOW pulse on the RESET pin (in the exact same way as the USB interface does).</p>

<p>During your startup procedure you read the GPIO pin you have chosen. If it's LOW the button is still being pressed in. If it's HIGH it has been released.</p>

<p>If you are using an Arduino with the normal bootloader the bootloader itself imposes a 2 second delay (which may be enough for you). Alternatively you will need to have your own delay in your program before reading the button to ensure that you have plenty of time to release the button so you don't accidentally reset your settings.</p>
