Skip to content

digiInBela

Reads a Bela digital input pin.

This opcode requires the Bela Csound host. See Bela digital input and output for setup, pin numbering and shared-pin rules.

Syntax

kstate = digiInBela(ipin)
astate = digiInBela(ipin)
kstate digiInBela ipin
astate digiInBela ipin

Initialization

ipin selects a digital channel from 0 to 15. It is required and fixed at initialization. Fractional values are truncated, then limited to this range. The opcode sets the pin to input on its first performance call.

Performance

kstate or astate is 1 when the pin is high and 0 when it is low. The k-rate form reads one digital sample per control cycle. The a-rate form reads successive samples throughout the audio block.

The opcode does not average the readings or debounce a switch. Use the a-rate form when transitions within a control cycle matter. For a changing pin number, use digiIOBela.

Examples

The example gates a quiet sine tone from digital input 0. Provide a defined high or low logic level with a properly wired switch or logic source, following your Bela board's wiring guidance. An unconnected input need not have a stable value.

A short smoothing time softens changes in volume. It does not debounce the input.

It uses digiInBela.csd, which must run on the Bela host.

Gate a tone with a Bela digital input
<CsoundSynthesizer>
<CsOptions>
-d
</CsOptions>
<CsInstruments>
// The Bela host supplies ksmps. Match sr to the board's audio rate.
sr = 44100
nchnls = 2
0dbfs = 1

instr GateTone
  kHigh = digiInBela(0)
  kLevel = portk(kHigh * 0.1, 0.01)
  aTone = oscili(kLevel, 440)
  out(aTone, aTone)
endin
</CsInstruments>
<CsScore>
i "GateTone" 0 10
e
</CsScore>
</CsoundSynthesizer>

See also

digiOutBela, digiIOBela, Bela digital input and output

Credits

Author Victor Lazzarini, 2017.