If the circuit does always have power,
than a simple flip flop does
1 | +-----------+ CD4011
|
2 | | |
|
3 | | +---)----------------+
|
4 | | | | |
|
5 | | +--|>o--10k--+--|>o--+-- on/off
|
6 | | + | | |
|
7 | Battery | | 1M
|
8 | | - | | _ |
|
9 | | | +--o o--+
|
10 | | | |
|
11 | | | 100nF
|
12 | | | |
|
13 | +-----------+----------------+
|
If you loose power, there are specialized
single bit non volatile state saver memory chips like
FM1105B, FM1106, FM1107, FM1110, FM1114 (RamTrom FERAM)
Of course you can program it also into a small micro controller
that has an EEPROM to save state during power loss.
For the Arduino programming environment
1 | char key=0, lastkey=0, savedkey;
|
2 | const char inputpin = 1;
|
3 | const char outputpin = 2;
|
4 | |
5 | void setup()
|
6 | {
|
7 | pinMode(inputpin,INPUT);
|
8 | }
|
9 | |
10 | void loop()
|
11 | {
|
12 | while(1)
|
13 | {
|
14 | key=digitalRead(inputpin);
|
15 | if(key==1&&lastkey==0)
|
16 | {
|
17 | savedkey=EEPROM.read(11);
|
18 | savedkey=1savedkey;
|
19 | EEPROM.write(11, savedkey);
|
20 | digitalWrite(outputpin,savedkey)
|
21 | }
|
22 | lastkey=key;
|
23 | delay(10);
|
24 | }
|
25 | }
|
So this is rather simple.