[vc_row][vc_column][vc_column_text]
It can’t be more interesting to light a lamp.
Change the color of LED Lamp RGB( red,green,blue), this lamp is consist of the three color emitting diode to realize variety of colors.
In this tutorial, you will learn how to use a RGB lamp to create the unique color combination.
Any color is possible according to the brightness of the diode.[/vc_column_text][vc_tour][vc_tab title=”Part list” tab_id=”1393910010-1-48″][vc_column_text]1. 1 x RGB LED
2. 3 x R 330 Ω
3. 6 x jumper lines
The longest pin is puplic pin ( ->GND)
[/vc_column_text][/vc_tab][vc_tab title=”Procedure” tab_id=”1393910010-2-45″][vc_column_text]The truth behind the analogWrite() function:
We can read the analog voltage( from 0 to 5V) through the analogRead() function on Arduino.
Is there a way that could make the pcDuino output the analog voltage?
The answer is Yes. Though the pcDuino do not have the true sense analog voltage to output, the pcDuino run fast and could use PWM to prevent the analog voltage.
Beside the analog port with the ~ port is compatible with PWM and the analog output.
PcDuino running speed is so fast that it can be on and off a light almost one thousand times per seconds.
PWM can achieve more by changing the consumption of time for high voltage and low voltage .
If it consumes most of the time in the condition of high voltage, connected to the structure of the LED light will be much more bright.
If it consumes most of the time in the low voltage state, then the LED light will be dark.
Because the blink speed at interface is faster than the speed of your naked eye can perceive , pcDuino creates a “true” analog output effect.
[/vc_column_text][/vc_tab][vc_tab title=”Key code” tab_id=”1393976711251-2-0″][vc_column_text]The key code
for (x = 0; x < 768; x++) {}
One for () loop is used to get a cascade in a range and constantly repeat run the code in braces {}.
The variable x start from 0 to 767, and add 1 (x++) at a time.
if (x <= 255) {} else {}
“if/else”: It is used to make the choose for the program. The statements in the parentheses () is a condition, if it is true, will run the the code in first curly braces {} , if it is false, will run the code in the second braces {}。
delay(sensorValue);
PcDuino running speed is so fast that it can run thousands of lines of code per second. We usually insert delays into the code if we want to slow down the code to see what is running . Delay is calculated on milliseconds (), a second includes 1000 milliseconds.[/vc_column_text][/vc_tab][vc_tab title=”Notice” tab_id=”1393977709003-3-10″][vc_column_text]You will see:
You should see the lights are lit up, but this is some of the new strange color.
If this is not the case, please make sure that your circuit is properly connected,
the code has been compiled and uploaded to the board, or refer to the troubleshooting tips below.
Troubleshooting:
LED lights to keep the dark color or display incorrect
Because the four feet of LEDs are very close to each other, sometimes it’s easy to make a mistake.
Once again confirm the position of each foot are correct connected.
See the red light
RGB LED lights in red may be more brighter than the other two , in order to make the three colors more balance,
you can use a bigger resistance or modify the code:
Modify the code
analogWrite (RED_PIN redIntensity);
to
AnalogWrite (RED_PIN, redIntensity / 3);
In the real world applications:
Many electronic devices, such as video game controller with RGB LED in the same area shows the versatility of different of colors .
Most of time different colors represent the different working conditions.[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.