i been thinking for the past few night and it seems that i may have found a way to emulate the keep function.
A keep function is just an equivalent to an Rs flip flop or to many electrician or people that know how to keep a relay on with hard wiring is called latch.
the basic for any latch in hard wiring is:
I1 I2 M1
---| |---|\|------( )
let say I1 and I2 are momentary push button, the I1 connection is the normally open while I2 is the normally close part of the switch that we are care about. M1 coil is the coil of a relay and M1i is one of the relay contact.
the operation goes that if someone push button I1, the circuit will be completed and current will flow . ( consider that the left side of the diagram is maybe 12V/5V/24/240V(live) for that matter and the right side is the ground/neutral). this will cause the relay coil(M1) to be energize and one of the relay contact will be close (M1i).Now the current will flow trough the (M1i) and down to the coil thus keeping the relay in the energize state (latch).....
to turn of this latch is as easy as pressing the I2 button, cause it cut the flow of current.
what happen if both the I1 and I2 button being press at the same time?
well because I2 is the one controlling the current flow, the coil will not be energies.in most way this make the circuit have some form of safety features.
how to emulate keep or latch inside arduino in term of programming?
i personally like to use the term keep but due to maybe making the wrong message across so i would use the second most use term to describe this behavior that is Latch.
int latch(boolean s, boolean r)
boolean result = LOW;
if ( (s== HIGH || result == HIGH) && r==LOW)
result = HIGH;
if (r == HIGH)