Page 1 of 1

Flip-Flop

Posted: Thu Aug 31, 2006 10:55 am
by ZONK
I have been experimenting with tut06 that came with sample Flow Code.
How do I generate a Flow code so that I can create a D type Flip Flop circuit i.e when a switch has momentarily made contact on Port A Ra0 for example, how can the Led on Port B rb0 be made to remain lit instead of going out when the input switch has been released and so that when a switch on port A on Ra1 is made momentarily, the LED on Rb0 goes out and then another LED on Port B rb1 comes on and stays on when switch Ra1 released.
Hope this makes sense

Posted: Fri Sep 01, 2006 3:41 pm
by Steve
I suggest you use a variable, STATE, to define which state the outputs should be (i.e. should RB0 be on or should RB1 be on). You could then react to changes in the input and set this state appropriately.

If you want to be neater, your STATE variable could flip between 1 and 2 as these values (when output to port b) will give you the required values of B0 and B1.

Here'a a pseudocode example:

Code: Select all

STATE = 1

loop forever
  if (STATE = 1)
    if (RA1 = on)
      STATE = 2
    end if
  else
    if (RA0 = on)
      STATE = 1
    end if
  end if

  output STATE to port b (with masking, so only b0 and b1 are affected)
end loop