BloxGaming Forums

Our Servers => BloxGaming SB3 => Expression 2 (E2) Code => Topic started by: kevinminion on September 03, 2015, 09:42:59 pm

Title: Change a non-toggled control to a toggled one
Post by: kevinminion on September 03, 2015, 09:42:59 pm
I was asked if I could make an e2 chip that would take a non-toggled input, like MOUSE1 from the Pod Controller, and make it so that MOUSE1 only needed to be clicked once to turn on, and then once again to turn off.
 
I came up with what I think is a good solution, but it does not involve an e2 chip, I just used a toggle gate and a constant value of 1:
 
Constant Value location: Wire Tab > Inputs, Outptus > Constant Value                   * I suggest that you make this one a favorite
Toggle Gate location:   Wire tab > Chips, Gates > Gates      MEMORY folder > Toggle (Edge Triggered)
 
Using the Advanced Wiring Tool, That's it!
Title: Re: Change a non-toggled control to a toggled one
Post by: kevinminion on September 03, 2015, 09:47:26 pm
So after I posted the message above, I thought it might be good to post code for those learning E2 since it's fairly simple.
 
Code: [Select]
@name example_e2_Toggle
@inputs OnValue OffValue Clk
@outputs Out
@persist IsOn
@trigger Clk
if (first()) {
    IsOn = 0    # start off
}
if (~Clk & Clk)   {   # Toggle on rising edge
   
    IsOn = !IsOn    # Toggle the state of the variable IsOn
   
    if (IsOn) {
        Out = OnValue
    } else {
        Out = OffValue
    }
}

Wire with Advanced Wiring Tool as described in the post above.
Title: Re: Change a non-toggled control to a toggled one
Post by: Bert John on September 03, 2015, 10:10:23 pm
The method i use for pulse wire to toggle is a memory d-latch and a logic not(invert) gates.


Wire data from d-latch to the invert, wire a invert to the d latch. Wire clk from d latch to mouse 1 or whatever.


Edit: Method found/Or made by Bloxgate