control trials of pake Arduino RGB LED is connected to the computer via the SerialPort, making the GUI on a computer with VB.net (visual studio 2008).
Here is a screenshot of the experimental results and photos:
Here is a screenshot of the experimental results and photos:
Program List for Arduino
/ / LEDRGB control program through the serial (RS232) 9600bps / / Microcontrollers: Arduino Duemilanove / / By: Aan Darmawan / / Date: December 26, 2010 / / How to control: information received from the serial code "000" s / d "999" / / Byte sequence control 1 red, 1 byte 1 byte green and blue / / 0 = means the darkest, 9 = mean terterang
/ / int ledrPin = 9; ledgPin int = 10; / / LED connected to digital pin PWM 9,10,11 ledbPin int = 11; faderValue int = 0; fadegValue int = 0; fadebValue int = 0;
void setup () {
Serial.begin (9600); / / enable 9600 bps serial communication
pinMode (ledrPin, OUTPUT); pinMode (ledgPin, OUTPUT);
pinMode (ledbPin, OUTPUT); } void loop () {
if (Serial.available ()> 0) / / read first byte of data as a red LED
{FaderValue = Serial.read ();
faderValue = (faderValue-47) * 10:34;}
if (Serial.available ()> 0) / / read second byte of data as a green LED
{FadegValue = Serial.read ();
fadegValue = (fadegValue-47) * 22:00;}
if (Serial.available ()> 0) / / read the third byte of data as a blue LED
{FadebValue = Serial.read ();
fadebValue = (fadebValue-47) * 25.50;}
/ / Send the PIN 9,10,11 (PWM)
analogWrite (ledrPin, faderValue);
analogWrite (ledgPin, fadegValue);
analogWrite (ledbPin, fadebValue);
delay (500); }
/ / LEDRGB control program through the serial (RS232) 9600bps / / Microcontrollers: Arduino Duemilanove / / By: Aan Darmawan / / Date: December 26, 2010 / / How to control: information received from the serial code "000" s / d "999" / / Byte sequence control 1 red, 1 byte 1 byte green and blue / / 0 = means the darkest, 9 = mean terterang
/ / int ledrPin = 9; ledgPin int = 10; / / LED connected to digital pin PWM 9,10,11 ledbPin int = 11; faderValue int = 0; fadegValue int = 0; fadebValue int = 0;
void setup () {
Serial.begin (9600); / / enable 9600 bps serial communication
pinMode (ledrPin, OUTPUT); pinMode (ledgPin, OUTPUT);
pinMode (ledbPin, OUTPUT); } void loop () {
if (Serial.available ()> 0) / / read first byte of data as a red LED
{FaderValue = Serial.read ();
faderValue = (faderValue-47) * 10:34;}
if (Serial.available ()> 0) / / read second byte of data as a green LED
{FadegValue = Serial.read ();
fadegValue = (fadegValue-47) * 22:00;}
if (Serial.available ()> 0) / / read the third byte of data as a blue LED
{FadebValue = Serial.read ();
fadebValue = (fadebValue-47) * 25.50;}
/ / Send the PIN 9,10,11 (PWM)
analogWrite (ledrPin, faderValue);
analogWrite (ledgPin, fadegValue);
analogWrite (ledbPin, fadebValue);
delay (500); }
Programming in VB.net (visual studio 2008)
Programming:
Programming:
Public Class Form1
Dim red, green, blue As Integer
Private Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ColorDialog1.ShowDialog ()
red = ColorDialog1.Color.R () \ 28.3333
green = ColorDialog1.Color.G () \ 28.3333
blue = ColorDialog1.Color.B () \ 28.3333
TextBox1.Text = red & green & blue
SerialPort1.Write (TextBox1.Text)
BackColor = ColorDialog1.Color
end Sub
Private Sub Form1_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.ReadOnly = True
SerialPort1.PortName = "COM2" 'Adjust to your computer
SerialPort1.Open ()
SerialPort1.Write ("000") 'RGB = 000 = black
end Sub
end Class
Note:
In the Object Properties SerialPort1, do not forget the series adapted port name
(SerialPort1.PortName) to those available in the PC / Notebook you.
Congratulations to experiment .....
0 komentar:
Posting Komentar