Hardware with Arduino & JavaScript

Face Expressions & LED Light Exercise

Steve Kinney

Steve Kinney

Hardware with Arduino & JavaScript

Check out a free preview of the full Hardware with Arduino & JavaScript course

The "Face Expressions & LED Light Exercise" Lesson is part of the full, Hardware with Arduino & JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Steve wires a color LED into the breadboard and updates the application to change the color of the LED based on the user's expression. Note: Ensure the LED uses PWM (~) pins in the breadboard.


Transcript from the "Face Expressions & LED Light Exercise" Lesson

>> We have connected the Get User Media API to some AI face tracking software to an Arduino to create a face Thurman. There you have it folks. Tell you what, I think it'd be fun to wire up the RGB LED, you can show different colors depending on what's going on as well.

If you look, this thing has four pins. It's an RGB LED, you always need a ground. I'll let you take a lucky guess why I picked the colors of the wires that I did. RGB red, green and blue one ground. Now, I will say this now. When I was going through this particular kit, I had to play around, I don't know if it was human operator error or when I did before but I'd like switch around some of the colors to get it to work right, so I am mentally prepared for that.

Maybe it was an operator error last time I did this. Maybe it's these are slightly different than I'm expecting. We'll find out together. We're gonna go with this initial layout first. And if I make it red and it turns green, we will adjust course accordingly either through code, probably we'll just do it in code.

So, we'll kinda get all of that in place as well. So yeah, as you can see, this one has four prongs, ground, R, G, and B. It's up to you if those are the colors of wires that you choose to use. I personally would suggest it, but you make your own choices, and I trust you.

Inherently so, you can try that out and let me know but I'm gonna try to do the same so I've got this RGB I used to say the bread board here and the longest pen, if I'm not mistaken, I can pull up the schematic just for the pen as well.

There's my face. I think the longest one is the ground, but it's one of those things which is I feel I'm pretty, I'm like 99% confident, but because you're all in the room, I am double guessing myself. I'm pretty sure that longest pin should be the ground.
>> You can't tell from that diagram.

>> I know. And at one point I definitely memorize this and I said do not forget whatever you do. And I've forgotten. But it stands to reason.
>> So, we don't have resistors in series with these, is that gonna be a problem?
>> I don't think so. In my experience, no.

How about that?
>> I think this has higher resistance, in a way.
>> And so I've plugged these, this schematic's different than, like, you can plug in any digital pins in this case. It doesn't really matter. Looks like I have it in 9, 10, 11. I know just in our live coding we have something in 11, so yeah, three digital pins of your choosing.

Bend that slightly so I can see it until also anyone looking at the film can see it. All right, we'll do the blue and I guess I'm gonna put this one. Eight, nine and ten. Eight. Nine, Get a little crowded on my board, it's all gonna be fine.

Ten. I just need something to go to the ground. I really want a different color wire, it's really important to me at this point. Like I said colors wires don't really matter. So it's you wire that I am gonna go flip over to my code to make sure that I am not insane.

At least I'm not wrong. For those watching my screen, it's very much like the LED, you just give it an array of pins. And so that will say RGB. So with Johnny-Five, it takes any CSS color, like the known ones like Blanched Almond. As well as the hex code color.

I said what I said [LAUGH] I don't see my light. So flash for a second there.
>> I think it's given me the wrong colors though.
>> That's what I said before, which is like I followed the schematic and I had the wrong colors. I had to like adjust the pin slightly.

So I am not surprised by that either. So we'll talk about how like
>> I got yellow, blue, and red. Should I get red, blue, and green?
>> Yeah, you might have, like I had to swap the numbers around and so. Yeah, so I think I said this before, I remember when I I had to, like, swap two of them.

So, out of hypothesis, I'm gonna swap the same ones I swapped last time. Like I said, it was not Let me see if that does the trick. Red. Blue, yeah, I am not totally sure, I know the experiences before. I don't know if it's the parts and these kits or what, but I had to swap it slightly, so normally they'd be an order.

I had to do it so the highest value. So it's basically three one two which is before when I tried it. I was like, maybe it's just me right now at this moment, so I was spiritually and mentally prepared for that but I had to swap those two.

And so like it was one of those things which is why you have to rep all it is very nice to be able to go in there and just like be able to change the column the rebel and get the feedback that you need, and be able to kind of make those adjustments on the fly.

That's one place where the REPL is just super helpful in this case. So I'm gonna go back to my face there, man, and I'm going to not have the music piece for a little bit. I know. We'll put it back later, you can put it back later. I'm just gonna comment out a lot of code.

It's gonna be okay. But I also, I'm gonna grab this and also see if I can get it to change colors based on my mood. Seems like a legitimate thing to do. So if I'm not mistaken, yeah, there's this expression. I'm just gonna sock and admit. If I'm already admitting the face, I could just admit it as the second argument as well.

So we'll omit the face position as well as the expression. We are going to slightly disable the piezo for a second. You can uncomment that line when you're ready, but just I think I've caused enough chaos with the audio. [LAUGH] For this workshop, I'm going to try to be at least a little bit polite to our friends at Frontend Masters.

Like a little, not a lot, just a little bit. So now we've got that. I'm gonna pull in that code where I swapped out slightly. Now when the face comes in, we've got ust console to date. I think it is all in that same Data, we'll start this up.

And I should see the X, Y, and the face expression, RGB is not defined, I called it LED. All right, starting up red. And if we go here. I got the X and the Y, might be the second argument then. So data, Expression. Am I sending that all through?

Rank expressions first face, let's save that Instead. Happy, okay, so now happy is coming in. So with that on the server side, we should be able just starting like this actually is just a helper function cuz actually gives you the weights and confidence for every single phase. When I'm like, I don't care about the weights and conferences tell me which one one, says all this function does is like literally just sort the keys.

So we'll send that there was a second argument, and back in we go and so now, If expression is happy, rgb.color green, I feel like angry should be red. We know that, right? Cool. [LAUGH] If expression equals angry, you've seen the movie inside out, right? Okay, just making sure if you're like, no, I haven't like, that's cool.

It's not actually important for this at all. And I forget what the other, was sad one, we'll have that be blue. So ideally now based on the expression coming in, I should be able to change the color of the RGB LED to my mood, right? Now how do I wire this up to a zoom meeting is the big question but, Just turned it off so far.

Some of these, somebody's work, so I got we can see go blue I wonder if not all the colors are represented in here or not all the above we got the faces right but,
>> You need a base case or like a default.
>> Neutral, you got neutral in there somewhere.

>> Neutral, but like that should just not trigger any my coach just leave the previous one, right? I mean, we've got the major point of this, right? [LAUGH] We can go, well, we'll see how that works. But, arguably, we're in the part of, Also wonder if I got those pins right but like we'll see in a second.

It starts out red. Angry. Happy seems to be problematic. It was a sad. Sad works, it's really just happy that seems to be the the issue right now and as I was playing around with I wonder if I've got the pins like totally correct, right? Because green would be if i have this thing flipped the wrong way, green will be the problematic one and because we're going back and forth.

I wonder if part of this is, I just got to flip it.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now