Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
|
This example brings together digital input and digital output. The program will read a button and turn the LED on and off according to the state of the button.
Before using the digital pins we need to set whether they are input or output. This is done via pinMode(context, 0, gInputPin, INPUT);
.
You will notice that the LED will normally stay on and will turn off only when the button is pressed. This is due to the fact that the LED is set to the same value read at gInputPin. When the button is not pressed, gInputPin is HIGH
and so gOutputPin is set to HIGH
as well, so that the LED conducts and emits light. When the button is pressed, gInputPin goes LOW
and gOutputPin is set to LOW
, turning off the LED.
As an exercise try and change the code so that the LED only turns on when the button is pressed.