Gate Input
Generic class for handling gate/trigger inputs through GPIO (Eurorack gates, triggers, etc.)
Features:
- Trigger detection (rising/falling edge)
- State reading (high/low)
- Optional inversion (for BJT input circuits)
Usage:
import nimphea/hid/gatein var gate: GateIn gate.init(D0, true) # Pin D0, inverted (typical for eurorack) # In main loop while true: if gate.trig(): # Rising edge detected! echo "Gate triggered" let isHigh = gate.state() hw.delay(1)
Procs
proc init(this: var GateIn; pin: Pin; invert: bool = true) {. importcpp: "#.Init(#, #)", ...raises: [], tags: [], forbids: [].}
-
Initialize gate input on specified pin
Parameters:
- pin - Hardware pin to use
- invert - True if pin state is HIGH when 0V at input (default: true for BJT circuits)
Note: Default is true because typical eurorack gate inputs use inverting BJT circuits
Source Edit proc trig(this: var GateIn): bool {.importcpp: "#.Trig()", ...raises: [], tags: [], forbids: [].}
-
Check if gate input just transitioned (edge detect)
Returns: True if gate just went high (rising edge)
Example:
if gate.trig(): # Trigger event - start envelope, increment step sequencer, etc.
Source Edit