Go Down

Topic: make an output latch? (Read 995 times) previous topic - next topic

jonisonvespaa

hi just gone through the examples for my first program id like to learn how to latch an output ie push button o/p stays on push button output off could someone point me in the right direction please
thanks

PaulS

Outputs are latched. You have to explicitly set the pin to HIGH or LOW. It does not automatically revert after some period.

kf2qd

I think the term you are looking for is that you want the outputs to TOGGLE.

It is rather easy to do -


declare a variable -
int toggleVar = 0;

inside of loop(){
   int ButtonVal;
   buttonVal = digitalRead(ButtonPin)
   if (buttonVal = HIGH ) toggleVar= !toggleVar;
   if (toggleVar) {
      digitalWrite(outputPin,HIGH);
   else
      digitalWrite(outputPin,LOW);
   }
}

I don't guarrantee my code will run as written, but it is an outline...

jonisonvespaa


Go Up