BrainClip Digital
This lesson covers the digital module.
Prerequisite
You must have completed the BrainClip Intro lesson.
Digital Output
A digital output is a pin connected to the processor that outputs (sets) a signal. This pin can be controlled to be ON or OFF. This on/off pin can be connected to a small LED (Light Emitting Diode), for example. The RGB LED module is just that.

The LED found on this module consists of three small LEDs built inside. Those three internal LEDs are Red, Green and Blue LEDs. Let’s start by connecting the pins as follows:
- P0 -> Red
- P1 -> Green
- P2 -> Blue
- GND -> GND


We can now use the Digital element to control an output.
var red = Digital(P0);
var green = Digital(P1);
var blue = Digital(P2);
red = Digital(P0)
green = Digital(P1)
blue = Digital(P2)
The Digital lesson covers further details on the Digital Element. The pin that needs to be activated will be set/written to 1. Note how this is on the output from the processor (the BrainPad) perspective. The out of 1 on red will make the LED Red.
var red = Digital(P0);
var green = Digital(P1);
var blue = Digital(P2);
Out(red, 1);
red = Digital(P0)
green = Digital(P1)
blue = Digital(P2)
Out(red, 1)
Mixing and combining different levels of Red, Green, and Blue (RGB) will allow us to create any color we desire. For example, Red and Blue make Purple.
var red = Digital(P0);
var green = Digital(P1);
var blue = Digital(P2);
Out(red, 1);
Out(blue, 1);
red = Digital(P0)
green = Digital(P1)
blue = Digital(P2)
Out(red, 1)
Out(blue, 1)
Since we are using digital output, we can only set a pin to on or off. We can’t set a level on a pin, meaning Red can be fully on or fully off. To control each color brightness level, we need Analog Output, which is covered in other lessons. The different combination of colors will result in 7 different color options plus OFF (black).
Digital Input
A digital input is a pin that is connected to the processor to read a signal (inputs) coming from a sensor. This can be a motion sensor, for example. Note how the signal is coming out of the module (OUT) and into to BrainPad. This means that modules needing an input on the BrainPad have a pad labeled OUT.

The Motion Sensor connects as follows:
- OUT -> P0
- GND -> GND
- VCC -> 3V
Note how we have chosen to use P0, but this can be a different pin.


We will read the pin (the motion sensor) in a loop, 10 times a second.
var p0 = Digital(P0);
while(true) {
Print(In(p0));
Wait(0.1);
}
p0 = Digital(P0)
while True:
Print(In(p0))
Wait(0.1)
Stop any movement around the sensor and observe the output when there is movement. Is the sensor immediate or does take a bit of time to detect movement?

Let’s try the same code but with the sound sensor this time. The connections are as follows:
- SIG -> P0
- GND -> GND
- VCC -> 3V


Observe the output when there is no noise and then see it change when clapping.

The Button is another input module. It can be used just like other input modules.
- OUT -> P0
- GND -> GND
- VCC -> 3V


Try the code from earlier, but note how pressing the button quickly will not show as pressed. This is because we check the input 10 times a second, every 100 milliseconds. If the button was pressed and released within 100 milliseconds, then the button press will not be seen by the processor.
Thankfully, the BrainPad API includes a special kind of function element that is more useful for buttons as it keeps track of button presses in the background and checks if the button was pressed or not previously. See Button Element lesson for details.
What’s Next?
Time to see how BrainClip Analog modules work.
BrainStorm
We speak of computers as zeros and ones. It is all comes down to an energized signal/pin and that is a one and an inactive signal/pin that is a zero.