Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Physical Computing with Arduino: RGB LED

0 (0 Likes / 0 Dislikes)
[ringing sound] [ADOBE DEVELOPER CONNECTION] [Kevin Hoyt - Platform Evangelist] Hi, I'm Kevin Hoyt, Platform Evangelist with Adobe. In this series, we've been talking about connecting hardware to Flash, specifically hardware using the Arduino prototyping board, and in this case I have a protoshield on top of the Arduino as well to give me a little prototyping surface and connecting that into Flash. [Working with RGB LEDs and Arduino] We'll walk through the details of this one. In this particular session, we're going to talk about an RGB LED, so red, green, blue LED, which is light-emitting diode. So rather than show you, "Hey, it's a red light," or, "It's a blue light," or, "It's a green light," a specific type of LED, what you can do is if you put red, green, and blue LEDs together and control the intensity of the light coming out of those LEDs, then you can mix them together and create any color that you can specify with RGB. You can wire those together. You can actually get RGB LEDs fairly inexpensively from online vendors such as They're great if you're familiar with how to wire them up with resistors and make sure that everything gets put in the right place. If you want to string more than one of them together, obviously that increases the wiring every LED you add. I actually really like this particular RGB LED. It's very bright. It's manufactured by BlinkM. That's It's got the RGB LEDs mixed in there together, already prepackaged with a little magnifier to brighten the light up. And then on the backside, it actually already has a chip in there to control the resistor, and we can also program the chip itself so that we can string these guys entirely separately, running and doing their own little thing. It also comes with some nice connectors for prototyping. So you just slap this guy on your Arduino and hook up the appropriate connectors, and you're off to the races. So that's exactly what we're going to do, and it's actually really easy. When you're working with your Arduino just by itself, you can take the BlinkM RGB LED and just plug it right in to the last bunch of pins on the Arduino stack. It sits right there, and that actually maps really well to just the default needs of one RGB LED. So plugging that guy in is just drop dead simple, and that's great. So now we'll go ahead and connect the Arduino to the computer. and then we'll talk about the actual application that we'll be putting on the Arduino to power this guy. Just like in the world of Flash where you might drop in a SWK library for other additional functionalities, we can do the same thing with Arduino. In this case, for the BlinkM chip, there's a library built using C and C++ that we can go ahead and include and use in our program. So the first line here is actually to include all the BlinkM functionality, and it actually uses what's called a one wire I2C protocol, so we include a library for using that as well. If we come down here, there are some variables, but mostly we're interested in taking a look at the setup function where we'll go ahead and say, "Begin the BlinkM, power it up, get it ready to go," and then just let it sit there and wait for some commands. Those are using functions that come to us by the inclusion of the additional BlinkM library. Then we'll go ahead and set up the Serial.begin so that we can actually send data over to the light and tell it what color it needs to be. So in our loop what we're going to do is listen for incoming serial data. Historically, in a lot of these sessions I've been sending data from the Arduino into Flash. We're going to go the other way this time, and it looks a little different, so pay close attention. In this case, we're going to listen for serial data as it comes in across the wire. When it's there, we're going to go ahead and read it. Now, in this case, what I'm actually going to do is keep track of the values that come in, and I'm going to assume they're going to come in groups of three: R, G, and B. And so I keep track of that, and I assign the red, green, and blue values. And when I've got a blue value with the third segment of values that I'll be sending in, I'll use another BlinkM function to actually tell the light to fade to this RGB color. You don't have to fade; you can just snap it to the specific color as well. The fade is a nice little effect. And you don't have to use RGB. If you want to use HSB, you can use that as well. So lots of nice functions pre-built for you there to specify whatever color you want. And so that's what's going on in the Arduino. I'll go ahead and hit the Upload button on the Tool Bar, and that'll compile the program and put it onto my board and then notify me when it's done. It takes just a moment. Okay, it's done. So now we have a program running here to power the light, and that is going to expect data coming in from Flash. It's going to get it from being able to go over the USB port. Flash obviously doesn't have USB connectivity, so we use TinkerProxy or serproxy. It's a little serial to socket shim or, in this case really, a socket to serial shim, a little tiny piece of software that runs in the background. Flash connects to that over socket, sends the RGB data across the wire, that lands itself on the Arduino. So let's look into Flash and see what that looks like. There's nothing in this particular UI. I'm actually going to use one of the components, one of the minimal comps you can find. It's a really great open source minimal component set. I'm going to go ahead and use that. It has a color chooser on that. I'm going to use that color chooser to allow the user to select what color they want. You'll notice I'm going to go ahead and instantiate that using the var color of type ColorChooser. That's the component itself. And then there's a socket, so socket this time is actually using the regular Socket class. Historically, when we've been getting data from the Arduino, we use the XML Socket class to send data over. I'm actually just going to use the straight up Socket class, and that'll allow me to write bytes and bits more effectively over to the Arduino. To instantiate the color chooser, it's really straightforward. Just instantiate it, tell it where I want it to be positioned, tell it to make out a default color information, and tell it what function to call if the color changes or the user selects a different color. And then I want to go ahead and tell it that we're going to use the pop-up to let the user select a color. They can also just enter the values. We'll set the visibility to false because I don't want it to actually show until we're connected to the system. And to connect to the system, I'll instantiate new Socket, add event listeners for when we're connected, and so when we're connected I'll make the color picker available. If we lose connectivity for whatever reason, I'll make that color picker go away. And then we'll go ahead and say socket.connect out to, in this case, that TinkerProxy or serproxy that is acting as the go-between from our socket to our serial port into the Arduino. When the color changes or when the user picks a different color, we get an integer value, which I'm using a little byte shifting to get the R, G, and B values out of. So once I've got the RGB values, I can go ahead and send that over, and I do that calling socket.writeByte. I write the byte of red, I write the byte of green, I write the byte of blue, and that comes over, gets the third color, and changes the color. The light on here is really bright and kind of hard to see individually. It shows up really great at night if you're trying to decorate your house or something along those lines. But in the case of a studio or kind of a demonstration case, I have this little case that diffuses the light and will make the color a little more visible for us to see. So I'll go ahead and run the program. There's our little color chooser. I'll go ahead and choose a color here, so let's go ahead and choose a blue, and the light turns to a blue. If I choose a green, the light will turn to green. I choose a different color--maybe a nice purplish. All right. So at this point I can tell it to change to whatever color I want from Flash, from user input, from any number of different sources. Maybe I want to sample the colors off of the incoming web camera. And if you string enough of these together, you might even be able to make your own little makeshift LED display. So that's an example of what you might do with RGB LEDs or be able to display red, green, blue colors from an LED on your Arduino and sending that data to the Arduino from Flash. That's it for this session. There's a lot more in this series of hardware and Flash connectivity. [For more information -,] Stay tuned. Until then, I'm Kevin Hoyt. [ADOBE DEVELOPER CONNECTION]

Video Details

Duration: 8 minutes and 53 seconds
Language: English
License: All rights reserved
Genre: None
Views: 157
Posted by: adobetv on Oct 21, 2010

You are a master at mixing red, green and blue in the digital world. Now Evangelist Kevin Hoyt shows you how to take that skill to the physical world using Arduino and Adobe Flash.

Caption and Translate

    Sign In/Register for Dotsub to translate this video.