When you only need one button
Have you ever written a simple Arduino application that just needed a single button? Most Arduino's and their clones have a reset button. Depending on your application you might find you can use the reset button as an input.
Recently I set up a robot arm for a display at an exhibition. It just sits on the table and runs through a set of pre-defined moves. I wanted to be able to adjust the speed but I did not want to spend time wiring up a pot, drilling mounting holes etc.
My solution was to store the speed variable in the EEPROM. The EEPROM memory can store information when the power is off or the processor is reset. According to the datasheet it should be good for 100,000 presses of the reset button. Every time the program runs the speed is incremented by a set amount and the new value is written to the EEPROM at address 0.
Now when I press the reset button the program cycles through 4 different speeds from 10 to 40 in increments of 10. Note: If your EEPROM has never been written to before then all bytes will be set to a value of 255. Below is an extract from my code.
#include <EEPROM.h> // you must include this to access your EEPROM memory
byte Speed; // this is my variable for a time delay
void setup()
{
Speed=EEPROM.read(0); // read the last speed setting used from the EEPROM
if (Speed<20 || Speed>40) Speed=50; // if it is not a valid amount then set it to 50. It will be 255 the first time
Speed-=10; // decrement my delay time by 10 every time the program runs
EEPROM.write(0,Speed); // store the new value back in the EEPROM for next time
}
void loop()
{
}



@ Thu, 2011-05-05 18:12
again, thank you! I had
again, thank you! I had never seen any programs using EEEPROM.
they always told me "do not touch to the eeeprom, it can only be used 1000000 times before dying!" (not sure of the number of zeros)
And as always your sketch is short and efficient :)
@ Wed, 2011-05-11 06:53
Parts are cheap
@ Thu, 2011-05-05 18:54
Glad to help. It is true
@ Thu, 2011-05-05 19:08
Welll sorta
As one guy put it your probably going to have fried your micro or have your project stolen by a dog before the EEPROM wears out.
so i use it regularly. Cool idea though. once though about this once just glued a button on a empty space.