Shop Learn
D Flip-flop to Stamp 2 — Parallax Forums

D Flip-flop to Stamp 2


Is there away to make a Stamp 2 to perform like a D flip-flop ? I tried every type of coding nothing works

Comments

  • @Rosalina1011 said:

    Is there away to make a Stamp 2 to perform like a D flip-flop ? I tried every type of coding nothing works. The D flip-flop is a 74LS74

  • JonnyMacJonnyMac Posts: 7,741

    Seems like you could debounce the input button and then use TOGGLE for the output.

  • Must be an interesting situation where you want to use a $40 Stamp to replace a 40 cent ‘74.

  • Tracy AllenTracy Allen Posts: 6,572
    edited 2021-10-11 15:29
    ' This as a state machine
    newstate VAR bit
    oldstate VAR bit
    upchange VAR bit
    outstate VAR bit
    
    main:
      oldstate = in0
      do
        newstate = in0
        upchange = newstate ^ oldstate & newstate    ' the XOR ^ detects change, the AND & restricts to low to high
        outstate = outstate ^ upchange.   ' the output toggles only when the input does low to high
        oldstate = newstate
      loop
    
    

    The input is not debounced, but that is also true of a D flip-flop. A little pause in the loop might work for debounce, just like a small capacitor on the input of the flip-flop.

  • I still love coming back to the BASIC Stamp. It is the cat's meow for BASIC programming skills. Here is the minimalist program, a full version for the BS2pe (or any). The LED is connected to pin p8 and the pushbutton is on p0 with pullup.

    ' {$STAMP BS2pe}
    ' {$PBASIC 2.5}
    oldstate VAR Bit
    newstate VAR Bit
    
    DIR8=1        ' output for led
    oldstate=IN0     ' input for pushbutton
    DO
      newstate=IN0
      OUT8=newstate^oldstate&newstate^OUT8.   ' logic for D flip-flop, execution left to right
      oldstate=newstate   ' update the state machine
      PAUSE 10     ' for debounce, too much, too little?
    LOOP
    
  • @tomcrawford said:
    Must be an interesting situation where you want to use a $40 Stamp to replace a 40 cent ‘74.

    It is. I would do things in reverse. Use the Stamp to configure the 40 cent '74. And produce an output.

    Never mind the fact that there are still four families of bobcats making themselves at home on the backlawn of Parallax.

Sign In or Register to comment.