Bela
|
Blinking an LED
This sketch shows the simplest case of digital out.
- Connect an LED in series with a 470ohm resistor between P8_07 and ground.
The led is blinked on and off by setting the digital pin HIGH
and LOW
every interval seconds which is set in render()
.
In setup()
the pin mode must be set to output mode via pinMode()
. For example: pinMode(context, 0, P8_07, OUTPUT)
. In render()
the output of the digital pins is set by digitalWrite()
. For example: digitalWrite(context, n, P8_07, status)
where status
can be equal to either HIGH
or LOW
. When set HIGH
the pin will give 3.3V, when set to LOW
0V.
Note that there are two ways of specifying the digital pin: using the GPIO label (e.g. P8_07
), or using the digital IO index (e.g. 0)
To keep track of elapsed time we have a sample counter count. When the count reaches a certain limit it switches state to either HIGH
or LOW
depending on its current value. In this case the limit is context->digitalSampleRate*interval
which allows us to write the desired interval in seconds, stored in interval
.
Generated on Sun Dec 22 2024 06:28:13 for Bela by 1.8.11