Showing posts with label RGB-LED. Show all posts
Showing posts with label RGB-LED. Show all posts

Wednesday, 19 November 2008

LED there be Light...

The plan to control the brightness of the LED.

Componets:
Arduino Board
Mini Bread board
Some Jump lead wires to connect it all up.
3 LEDs (Reg, Green, Blue)
3 resistors.

Based on the Fading example on the Arduino site, and provided in the Arduino development environment, I wired up the 3 LEDs to the Arduino board. Then modified it to control 3 LEDs.

To get a bit more cleaver I wanted to control the light from the computer, the Dimmer example provided the basics for the implementation from the Arduino board side of things.

For the coding on the laptop I decided to implement this in Java. The reason for this is Java is something I know my way around well. With the Arduno code which is based on C/C++ I am just winging it at the moment.

If this is the first time you want to communicate over a serial port in Java code you'll need to install some Operating System dependant libraries. This surprised me a bit, but found the following link, which provided the info required. Go with the rxtxSerial libraries not SUN's javax.comm package, its not good gave me some grief.

The link for installing the libraries also had some sample code for implementation which I happily blagged and modified in order to knock up a bit of Java to display a JColorChooser component, hooking the code to send the selected colours RGB values to the Aruino to change the colour of each of the LEDs.

After some playing/searching/thinking decided on a go with the format o #RRGGBB, with colours represented as HEX, and pad if the value is less than 10, to get a consistent 2 digits for each colour value.

On the Arduino side the following function takes care of reading the data in. The serInStr array and dataLength, are sized to the expected 7 so that takes care of reading a complete value each time.

//read a string from the serial and store it in an array
int readSerialString () {
int i=0;

if(!Serial.available())
{
//Serial.println("No Data");
return -1;
}
while (Serial.available() && i < dataLength)
{
int c = Serial.read();
serInStr[i++] = c;
}
Serial.println(serInStr);
return i;
}

Works really well so am pleased with progress.
Next on the the scary bit, trying not to cook the accelerometer. LEDs about £1 not bothered if i cook them, the accelerometer £27, that would annoy me somewhat.

Tuesday, 18 November 2008

Where it started...

The goal of this project:
Think, holding a Rubik's Cube, whatever side is facing up, is the colour the lamp on the other side of the room will change to. As the cube is rotated the light will change.

The plan:
To build this using an Arduino Diecimila open source board(x 2), RGB LEDs, 3 Axis Accelerometer, and wirless transmitter/reciever.

Floating around in the back of my head for a while has been the idea to play with intelligent or automated control systems, without a any specific plan or project in mind.

While fossicking around the internet a while back I came across a project on the instructables.com web site (had not heard of this before), which I looked at and thought was pretty cool, it showed a RGB LED being controlled wirelessly using an Accelerometer to control the colour, see here. I was holding a Rubik's cube at the time, and was thinking how cool would it be to rotate the cube so that the colour facing up would be the colour the LED would emit and while rotating, would gradually change between these colours.

One of the components was was an 'Arduino wee' Searching for this I found discovered the Arduino site
and the 'Arduino Diecimila' an Open Source electronics development platform,

A few days passed and the idea kept growing on me and the 'thats pretty cool' factor hadn't waned. So I went shopping for the bits, as this is something I know very little (nothing) about I decided on a run before walk approach, so I only ordered a couple of core components, the 'Arduino Diecimila' board, and the Accelerometer.

I started this a week or so ago, so will post a couple in quick succession in line with my progress, rather than one huge post.

So it begins...