Pages: [1]   Go Down
Author Topic: make an output latch?  (Read 803 times)
0 Members and 1 Guest are viewing this topic.
uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 310
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 553
Posts: 46300
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1023
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 310
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for the help
Logged

Pages: [1]   Go Up
Jump to: