Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
This sketch shows how to control a digital pin synchronously from your code. This is an alternative approach to using the Bela Digital I/Os, which are sampled at audio rate. With this approach, the sampling time is not periodic.
Examples use cases:
--disable-led
).See here for more details: https://github.com/BelaPlatform/Bela/wiki/Using-arbitrary-GPIO-pins
In this example we use as an output GPIO pin 89, which on Bela is P8.30 and on BelaMini is P1.04, but is also connected to the on-board red LED. Additionally, we read the button on the Bela cape. DO NOT press the button for more than 2 seconds at a time, unless you disabled it globally on your system, or you will trigger the default action (system shutdown).
Preparation:
On Bela:
--disable-led
In both cases, you have to disable the default behaviour of the button on the cape by running with --disable-cape-button-monitoring
. Again, DO NOT hold-press the button for more than 2 seconds at a time unless it is disabled globally.
The led is blinked on and off by setting the digital pin to 1
and 0
every gInterval
seconds, unless the button is pressed, in which case the blinking is temporarily disable.
In setup()
the pin is opened and initialized as an output mode via a call to Gpio::open()
.
In render()
the output of the output digital pin is set by Gpio::write()
, and the input digital pin is read calling Gpio::read()
.
To keep track of elapsed time we have a sample counter gCount
. When gCount
reaches the desired value, it switches the state of the LED pin.