Take a Nano for example. Normally when you press its reset button, all variables would be cleared by the compilers initialization code.
But there is a way to tell it not to reset a variable, to make it non-volatile through a reset.
This means you can choose from a few options by simply pressing the reset button on the Nano, with no external selection controls.
Simple usage examples could be a servo with (say) four different positions, selected by pressing reset, or a two-option on/off 'switch'.
Another use might be to give a random number generator a different seed after every reset, rather than the same 'zero' seed every time.
Maybe your project has used all the available I/O but you need just one more option to choose the red pill or the blue.
I used it for a 'demo loader' for a recent Retro Computer Festival:
Code: Select all
// use reset button to select option 1 to 4, Phil_G
int mode __attribute__ ((section(".noinit")));
void setup() {
Serial.begin(9600);
Serial.println("Press reset to change mode");
mode++;
if (mode > 4 || mode < 1) mode = 1;
Serial.print("Current mode: "); Serial.println(mode);
}
void loop() {
switch (mode) {
case 1: // do mode 1 stuff, say "servo neutral"
break;
case 2: // do mode 2 stuff, say "servo right"
break;
case 3: // do mode 3 stuff, say "servo neutral"
break;
case 4: // do mode 4 stuff, say "servo left"
break;
}
}
Of course since nothing has been saved to eeprom, power-off doesnt save the variable. To retain a value during power-off, you would need to write it to eeprom, but what if your project does fast, sequential writes? the eeprom write limit could easily be exceeded. This could be a means to avoid that, it all depends on your project and circumstances. I think this is just another interesting option
Or maybe I'm late to the party again and everyone else has been doing this for years!
Cheers
Phil