LED Brightness Control Module
This module allows you to control the brightness of devices such as LEDs. You can enter the pin number to which your device is connected and vary the brightness.
If your device is connected to a digital pin, you can turn it ON or OFF by pressing the power button in the centre of the screen.
If your device is connected to a PWM pin, you can vary its brightness by sliding the green bar in the clockwise direction.
The LED Brightness Control is the first module of the Dabble App.
This module allows you to control the output of the digital pins in two ways:
- If the pin is a digital pin with no PWM support, then you can control the HIGH and LOW state of the LED by clicking on the ON/OFF icon present in the center of the module.
- If the digital pin is a PWM pin, then you can also control the brightness of the LED, using the module. You can adjust the brightness value between 0 to 100 using the potentiometer type knob.
How to change the Pin?
To change the pin, you can click on the button showing the Pin (In the above image it is Pin: 13 button).
You can choose the following pins for the corresponding boards:
- PWM pins: digital pins 2-13
- Digital pins with no brightness control: digital pins 21-26
- Arduino Uno:
- PWM pins: digital pins 3,5,6,9,10 and 11
- Digital pins with no brightness control: digital pins 2,4,7,8,12 and 13
- Arduino Mega:
- PWM pins: digital pins 2-13 and 44-46
- Digital pins with no brightness control: digital pins 14-43 and 47-53
Enable LED Control Block
To access the LED Brightness Control feature for the very first time, you have to upload the following script.
As you can see, there is a stacked block named as “ enable LED control” snapped to the evive Program block. Its function is to enable the LED Brightness Control feature of Dabble.
To include the LED Control module in the Arduino program, you have to include the following header:
After defining the above mention headers, you have to include the dabble library:
You can download the library from here:
Enabling Bluetooth Communication
To enable Bluetooth communication, you have to initialize serial communication using the following code:
Here Baud_Rate is the baud rate set for the Bluetooth module. With evive, you normally get 115200 baud rate modules.
Refreshing the data
To refresh the data that the device has got from the mobile app, you have to use the following line of code:
This function also change the state and the brightness of the LED automatically and you don’t have to do anything.
If you want to get the pin number, its state and brightness value of the LED from the module, then these are the functions using which you can do that:
- LedControl.getpinNumber(): This function returns the pin selected for LED Brightness control in the mobile app. The function returns int data type.
- LedControl.getpinState(): The function returns the state of the pin set by the user in the mobile app. This function returns the following output:
- 1 if the state is set to ON
- 0 if the state is set to OFF
- LedControl.readBrightness(): This function returns the brightness value set by the user in the mobile app. It returns int data type with a value ranging between 0 and 100.
Here in this example, we are controlling the LED brightness and also displaying the pin number, state, and brightness of the LED on the serial monitor.