0% found this document useful (0 votes)
2 views

01 RGB Control

This document provides instructions for controlling the RGB LED on an Arduino expansion board using onboard buttons. It includes a program flowchart, setup instructions, and code analysis for reading button status and changing LED colors. Additionally, it offers troubleshooting tips for program upload issues and guidance for modifying LED colors.

Uploaded by

Ywhite Eric
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

01 RGB Control

This document provides instructions for controlling the RGB LED on an Arduino expansion board using onboard buttons. It includes a program flowchart, setup instructions, and code analysis for reading button status and changing LED colors. Additionally, it offers troubleshooting tips for program upload issues and guidance for modifying LED colors.

Uploaded by

Ywhite Eric
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

RGB Control

This lesson aims to read the status of the onboard buttons on the Arduino
expansion board, achieving the control of the RGB LED color.

1. Program Flowchart

2. Onboard RGB LED

The three RGB colors of the onboard RGB LED can be separately set to light
up. This enables the RGB LED to achieve a colorful display effect.

3. Program Download
Note:

 The Bluetooth module must be removed before downloading the program, otherwise

the program download will fail due to serial interface conflict.

 Please turn the switch of the battery box to “OFF” when connecting the Type-B

download cable in case the download cable touches the power pin of the expansion board

by mistake, which may cause a short circuit.

1)Locate and open “rgb_test” program file in the same dictionary as this

1
section.

2) Connect the Arduino to the computer with the Type-B cable.

3)Click the “Select Board”, and the software will automatically detect current
Arduino serial interface. Then click to connect.

4)Click to download the program to the Arduino, and then wait for the
download to complete.

4. Program Outcome
After turning on the robot, the RGB LED on the Arduino expansion board will
be red. When the KEY1 button on the expansion board is pressed, the RGB
2
LED will turn red; when the button is released, it will switch back to red.

5. Program Analysis

5.1 Import Library File

Import the required RGB control library for the game.

5.2 Define Pin and Create Objects


1) An RGB LED pin and a button pin are defined.

2) Create an RGB object and a variable for storing button status.

5.3 Initial Settings


1) Initialize related hardware equipment in “setup()” function. The first is serial
port. Set its baud rate of communication to 9600.

2) Configure the button pin as an input IO, with a default low voltage level
value after powering on. Initialize the RGB LED on the expansion board via the
“FastLED” library. Connect it to the “ledPin”. Call the “Rgb_Show(255, 255,
255)” function to set the RGB color to white.

3
5.4 Main Function
In the “loop()” function, use the “analogRead()” function to read the value of
the button pin. Determine the button pin value to control the color of the RGB
LED. If the read button pin value is 0 (low voltage level, indicating the button is
pressed), the color of the RGB LED is set to white; If the read pin value is 1
(high voltage level, indicating the button is released), the color of the RGB LED
is set to red.

5.5 RGB Control Function


In the “Rgb_Show()” control function, the color of the RGB LED is set by
passing three parameters. “rValue” corresponds to red; “gValue” corresponds
to green; “bValue” corresponds to blue. The values of R, G, and B range from 0
to 255. Then, call the “FastLED.show()” function to display the corresponding
color.

4
6. Function Extension
How to modify the color of RGB LED from red to green? Please refer to the
following instructions:
1) Locate the function “Rgb_show()” for controlling the RGB color in the main
program. The three parameters of the function correspond to red, green, and
blue respectively.

2) Modify the value of red to 0 and the value of green to 255. This allows you
to change the RGB color to green.

For more detailed information about the RGB color table, please access:
https://www.bchrt.com/tools/rgbcolor/.

7. FAQ
Q:The code fails to upload. What should I do?
A:Please check if you have connected the Bluetooth module to the robot. If so,
please remove the Bluetooth module before downloading.

You might also like