Author Topic: Change a non-toggled control to a toggled one  (Read 9759 times)

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Change a non-toggled control to a toggled one
« 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,
  • Wire the input OnValue of the Toggle gate to the constant value output of 1.
  • Wire the input Clk of the Toggle gate to the MOUSE1 output on the Pod Controller.
  • Wire the input FIRE of the weapon to Out output of the Toggle gate.
That's it!

kevinminion

  • Global Moderator
  • Full Member
  • *****
  • Posts: 147
  • Karma: +15/-0
    • View Profile
  • IGN: Kevin Minion
Re: Change a non-toggled control to a toggled one
« Reply #1 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.

Bert John

  • Administrator
  • Full Member
  • ******
  • Posts: 139
  • Karma: +17/-8
    • View Profile
  • IGN: Bert John
Re: Change a non-toggled control to a toggled one
« Reply #2 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
« Last Edit: September 03, 2015, 10:41:06 pm by Bert John »