ARDUINO TUTORIAL 68: Make a Remote Controlled RGB LED with Brightness and Color Control

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is polemic order from top tech boy comm and we are here today with lesson number 68 in our legendary our epic new series of arduino tutorials I will need you today to pour yourself a nice huge mug of iced coffee you will need it because today is time to check your homework in lesson number 67 we left you with the homework assignment and that homework assignment was to create a remote-controlled RGB LED where you would be able to control the on-and-off nosov the LED the color and the brightness okay I need you guys to pause and go down and leave me a comment did anybody even try to do this by themselves or did you just sit back and eat some potato chips and wait for the new lesson to come out when you could just copy me do it you guys are never gonna learn how to do this until you do things on your own because when you do things on your own things get very very painful and you've got a dig and you've got a struggle and you've got to try and you've got to figure it out and then all the sudden you figure it out and then life is wonderful the sky's a little bit bluer you hear the birds outside chirping life is wonderful when you figure things out did anybody try to do this homework and of the people that tried it did anybody get it all working the way I said to get working if you got it working write me a comment down below I am Legend okay because this assignment really seemed pretty easy but as you did it it probably turned out to be a lot harder than what you thought and so let's go back and review what the assignment was the assignment was to control an RGB LED with your remote which you can get in your fabulous eel egg ooh kit which is available in a link down below it does help if we are in the disc it does help if we are using identical hardware and what what the assignment was was to control the RGB LED in the kit using the remote in the remote receiver module that are in the kit and like we say I've kind of moved from the Arduino Uno that came with the ELA goo kit and I've moved to an Arduino Nano with the links available down below really suggest you guys get you a nano because it's just so much easier to make a nice neat build when you have a nano okay so what was the assignment the assignment was to control the RGB LED from the remote if you press the on button you were supposed to come up in white okay in white light full brightness if you press the function stop button it was to turn off then zero was to be for white one for red two for green three four blue four for cyan five for magenta and six for yellow okay so depending on what button you press you get different colors now this was racked through you a little bit of a curve ball and it would require you to actually go in and think through this and come up with an algorithm that would always work and what the assignment was was for the down key to turn the brightness down so every time you hit the key dim dim dim dim dim and then every time you hit the up key brighter brighter brighter brighter up to the maximum brightness and the kind of curve ball I threw you like if I turn on red it comes on let's say I turn power on it's full brightness I didn't go to red it's full brightness if I go dim dim dim dim four dims and then if I go from red to green the green should come in at the dimness the four dims that I set on red so that the dimness should go from channel to channel the channel as your change in color was anybody able to figure that out might have run into a few more problems along the way did you figure those out if you got everything working like I said and I am Legend if you didn't type in what the problem that you had before we go through this because if anything I want you to start seeing how I think and I want you to start seeing how to debug things so you know my videos are longer but that's because as I'm going through them I'm talking out loud and you can sort of start seeing how to think like an engineer okay so let's just jump right into this I think where you will want to start you will want to start by going to the fabulous ww tech boy calm hopefully I can find this yeah here we go let's see give me just a second here I've got to get up I need you to go to top tech boy calm and I need you to go to lesson number 65 which I am in the process of doing here okay I need to go to post and I'll show you this in just a second okay so let me show you my screen top here hopefully I will show you my screen that is not the right one I think it is this one and I apologize I am going to have to correct this it's not finding the screen sight I've got to go in and tell it the screen I am so sorry okay screen capture sometimes my production software gets a little confused that is not good we will get this boom okay it sometimes loses which screen is which and so just be patient with me I am a one-man show here okay go to Arduino tutorial 65 on WWE top tech boy comm we show you how to hook this thing up and then I've got the code from where we're starting so I'm gonna get this and I'm gonna copy it and then we will come over to now I can really go to where I wanted to go to earlier I have lost every okay here we go I promise this time I promise I promise it's going to work okay I think we are where we need to be now so we are going to come to this and we are going to paste that code and let me make sure that I got it I do need my I do need my keyboard back here ctrl C now come over here control a selects everything control V okay so now you should be up to where I am with the code and now let's look over here and see what you're going to need for the bill I feel like I've gotten off to a little slow start on this video but we are gonna work on through okay you're gonna need your RGB LED you're gonna need your from your a Lego kit your infrared receiver module you're going to need your remote control three current limiting resistors 220 or 330 ohm works well you can use your Arduino Uno I prefer using the Nano if you haven't gotten a nano yet look in the description down below there's a link allows a lot neater build so okay and then you need some of these jumper wires so let's look here and see how we have this hooked up again this is explained in lesson number 65 I have from the Arduino I will show you here I have from the 5 volt pin come up and I stablish this top row as 5 volts and then coming down I jump earth at 5 volts down to the second from the bottom rows so that's also going to give me 5 volts on the IR receiver module the left pin which is labeled G the left pin which is labeled G focus you aggravating thing ok left pin G goes to ground the middle pin R goes to the power rail the 5 volts in the right pin W goes to pin 9 on the Arduino and that is where we left you at the last video so let's come back and download that and just make things sure things are still working because guys you know before you do a complicated bill just make sure we're like where we were before we had this working before let's make sure it works so as I press these buttons I should see commands come up here so if I press PWR ok I see PWR pop up so that's good if I press 0 I see 0 so the remote is working that's very very good the remote is working so we are indeed where we left off in lesson number 65 now I'm going to give you a nice overhead view and you can kind of go through this build with me I think this would be the suitable view and I will do my best to keep things in in your field of view so first thing we got to figure out what we're gonna do with the RGB LED understand that there are different RGB LEDs out there and I'm giving you the one that comes with the Lego kit now if you notice on the e Lego kit there is one leg that is longer than any other ones in this orientation it is the second from my left it is this pin here is the long one and so if you look over here at this picture that I've drawn you that long leg is ground when I have it oriented like this the pin to the left of it is the red pin and then you go red brown green blue okay and now since I'm gonna want to control brightness am I going to want to use digital pins or PWM tents those pins that I can do the analog right to I want to use the squiggly pins because I might want to adjust brightness you know that was part of the assignment so step one you better have selected squiggly pin so I'm going to nan is already used man wouldn't it have been nice to use nine ten eleven but nan is already used for the remote and I don't want to redo that code so I'm going to leave nine on the remote and I'm gonna go six for red then ground then 10 then 11 alright so now you know if you've been watching me do these builds I do not like to bend wires and so I like to keep my wires nice and straight so what I'm going to do is I'm going to plug these wires and over here on those digital pins and then I am going to put the LED where these wires would want them to be based on how long they are you can also get rolls of this wire and bend it yourself and that way you can make each wire the exact length but I don't have such a setup right now I'm just using these pre-made ones which are quite convenient so let's get this and kind of look at everything so I want to start at pin six and so I will come over here on the Arduino and man guys check this very very carefully like right there that is not pin 6 that's pin 3 I already made a mistake so I'm gonna pull that out and then I will come over here to pin 6 ok then over here it seems like pin 6 wants to just kind of naturally plug right in there so I'll do it like that and that's pretty straight that's not perfect but it's pretty straight ok then the Green was going to be 10 10 so I will jump over man yeah 6 and then I will come over here to 10 I'm going to kind of plug it in up high and then it wants to go right there and now I am left with 10 11 for blue and so I come in to pin 11 and it wants to go right there okay you see how I have that hooked up alright so never fear you're not going to have to bend these LED pins and I don't want to build bend the pins on the LED what I've just got to make sure is I've got to make sure that I've got this in the same orientation as this picture I don't want it like that that's not what I have in the picture it's like this where the long leg is towards the left and now I'm just going to come and I'm going to plug it in in the general vicinity in the general vicinity of these wires that I brought over but I'm going to put it in the top half the board because right those connections are broken through the trench and so I'm going to put it in the top half of the board and now rather than running wires from here to here I'm just going to jumper across my current limiting resistor so I'm going to come to my red pin which is the left pin and then what did I want that to go to I wanted that to go to the wire connected ten six okay and so that is and I missed it on the top there all right so let's check it okay do you see that it's in there in a common column with my red pin on the led coming down to the wire that goes to pin six then similarly I'm going to come the green pin to the wire that goes to pin 10 and just as a good practice I don't like to build with that plugged in so I'm going to unplug that and try to keep these as straight as I can and as lined up as I can okay that looks pretty good and now my blue pin is going to go from the blue pin on the led down to that wire that goes to pin 11 okay so this resistor goes to the blue pin on the LED the blue pin the rightmost pin and that comes down to the wire that goes over and connects to pin 11 on the Arduino so we should be hooked up somebody tell me what we forgot tell me some someone tell me what we still have to do we still need to ground this okay that second pin that long pin we need to ground now I could run a wire from here all the way down to my ground rail but that's going to be going through the resistors and over this wire so I don't want to do that what I'm going to do is I'm going to make this top I'm going to make this second to the top row also a ground by jumping it to the GND wire on the Nano so I will come from GND pin on the nano over like that and now that has been established as a ground rail now I can come in in that ground pin on the led I can ground to that ground rail and don't force it just kind of jiggle it till it goes in very nicely okay do you see that all right that is looking pretty good I believe I have everything hooked up now so I'm look at that our little our little module fell out so I'm going to very carefully put that back in as such okay that looks good now what we're going to do is we are going to come and we are going to put the power back on all right now let's go back to our view here hopefully those windows are still going to be a lab okay that one's alive and let's see if that one's alive yep that one's still alive so sometimes the production software loses these windows and I have to go put them back on okay I believe we verified earlier that our software was working if I hit please work is it working okay oh did I download this all right let's make sure I'm going to download this lesson 65 it's not happy okay it's downloading that I'll come over here let's just make sure we were where we were before I hit PWR oh it's still downloading I'm sorry downloading lesson 65 and then you're watching this little thing here is to see if it gets the PWR we did get a happy little blink we get a PWR let's try the function button I hit fu n happy little green light fun okay so we verified after adding the LED and after doing everything else the remote is working per the lesson that we did in Lesson number 65 and so now we are ready to start working with we are ready to start working with the LED and so I need to get my keyboard in here and okay so first thing I want to do is I just want to kind of see if that LED is going to work if I have it hooked up right and so we're gonna have to add some things to talk to that and so we have three pins right so I have the int and what do I have I have the our pin and where did I say the our pin was it was pin six try to get it where you can see all of this okay and let me see if I can make sure let me just get let me take a second and get it where you can see it well okay get some focus going here okay so what we want is we want red pin is pin six and so I can go back to the code view and so I have integer red pin our pin is six and then if we look over there next up we had G pin green pin is equal to ten and then we have int beat int B n is equal to 11 all right now if we set those things up we're also going to need brightness values so I'm going to say R right int since we're gonna be doing dimming we in in you know we ought to think right off the bat since we're gonna be doing dimming we better have variables for the analog rights so we're going to have our bright and we'll just start things off at 2:55 and then int G for green bright it's equal to 255 and then int be bright equal to 55 all right now also I'll just I'll just leave it at that for right now okay now down in our void setup what we want to do is we want to do our pin modes so pinmode our bright is output pin mode G right is a what it's an output and mode B right is an output okay before we do anything else I just want to see if I can turn this led on it's the LED good right it you know is things set up just see if we can turn it on I like to check things before I get too far into this so I can do a digit all right our oh man did you catch this this is our pin sheep in a pen like that is outputs now digital right our pin what do I want to write I'm just going to turn it on 255 okay digit all right Jeep in 255 it's easier than writing the variables and I'm going to take this out after I see that it works good you'll write write the pin 255 okay when I do this the LED should turn nominally it should turn white okay let's see if we can download this it should turn on kind of white even before I do anything at all it's downloading downloading downloading okay so the LED turns on and it looks nominally white I like to use these little ping-pong balls that I drill a nice little hole in and then I like to put them over there as kind of like a little lamp I think it makes it look nice I do note that when I turn all three on full brightness this has a little bit of a blue tint tint to it so I'll play later on want to turn my blue down a little bit but we've can fine-tune the colors later what is good what is good is is that this thing is actually we're you know turning on so I got the LED hooked up right I got the remote hooked up right so now we are ready to start doing some coding let's take care of the on-off first but me guys we got to think through this there's going to be a lot of if statements based on what button is pushed and your temptation is going to be in each if statement to put like set the brightness levels in the if statement and then turn the values on analog right in the if statements I'm not going to do it that way I'm going to use the if statements to set up the parameters so like if one is pressed if the button one is pressed I'm gonna set the parameters where I'm ready to turn the LED red so that would be like our brightness equal to 55 G brightness equals zero B brightness equals zero and then after I go through all of the if statements then I'm gonna do the analog right at the bottom after all the if statements so the if statements are going to be setting my parameters up and then at the end I always just have one you know one set of analog rights outside of those if statements and if you try to do all your bookkeeping inside the if statements I think that would be a really hard way to do it so you guys leave me a comment down below if you tried that and failed or if you tried it and got it working okay so now we're going to go through all of these if statements are just seeing which button has been pressed and so what this code does is it's starts up here and the first thing it does is it just waits for a button press so nothing's going to happen till a button is pressed and then once the button is pressed it reads the value the little remote here the remote module infrared module reads the value from the remote and then converts it into kind of a meaningful command and so that's what all this does so we'll let it figure out what button has been pressed and now we need to do our if statements so what would we do if well what happens if you press the power button let's see because I wanted it to come all the way on but I have to know what that command is so I'm gonna point it press it and then what I can see is is that the string that comes from the PW from the power button is PWR so if my my command equal equal the string PWR what do I want to do well I want our right to be equal to 255 I want G bright to be equal to 255 and I won't be bright to be equal to 255 all right also what you got to kind of think is we started talking about dimming and we're gonna have to deal with this dimming function later and so I need some parameter like the dim factor defect okay and the dim factor you know I could be at a hundred percent 90 percent eighty percent that sounds like not an int but a float and so I'm gonna float defect or like what factor do I want to dim by and I'll just set it one so one would be full brightness so mentally one would be full brightness 0.1 would be 10 percent bright point nine would be ninety percent broke okay so I'm gonna float that and what did I say that if I hit the power button if I hit the power button what brightness what I want I would want full brightness so I'm gonna just put in here defect is equal to one now you might be thinking that well why do you need that cuz you're it is but yes go with me here if you can do it without using all these variables show me that it really works but I think this is a good way to do it so that is that now I'm going to come up and I'm going to copy that and then what else do we want to do let's go ahead and turn it off let's figure out how to turn it off so that was supposed to be the little function stop button in the upper right so if I click that I can see that the command that that sense is fu in so then here what I'm going to say is if my comm equal equal what if you in the string if you meant and if it's equal to fun then what do I want to do well I want our bright to be equal to zero I want G bright equal to zero I want be bright equal to zero and then just for fun the D factor is going to be equal to zero now you might argue this is redundant and it might be but I'm just trying to keep track of the brightness values and then also keep track of this dim value and so maybe later on you'll see what I'm doing this maybe you've got a better way to do it but this is just the way that I'm doing it now I think that this should be able to turn on and off I need everyone to hold their breath Oh denied denied oh my goodness D fact somebody did not hold their breath and that was the problem and defect didn't have a semicolon this time everyone hold your breath boom it downloaded okay and why did it come on because we forgot to take this nonsense out here when we were testing the LED that turned it on and so remember these digital rights we did we forgot to take those out so I need to take those out and also I forgot down here I set things up but I never did the analogue right so I need to go ahead and do that after the if statements now those parameters that were set up I'm going to write them in so I'm going to say analog right and then our pin I'm gonna put our I'm going to put in it our right and then analog right G pen G right and then I'm going to write to [Music] what beep in the blue pen and what B brightness so this should be a simple on/off function at this point so let's download that I'm not going to hold my breath I have absolute confidence that this is going to work absolute confidence you can't see my little green bar so I'll skip that all the way you see look at me I'm as cool as a cucumber this will work okay it downloaded now let's see when I press the power button in the serial monitor you should see PWR and then you should see this turn on okay uh-huh I just turned a lot on by remote control yeah okay oh it's a tad bit bright in here I think I'll turn it off with the fun button huh look at that who's turning lights on and off giddy up giddy up we got this thing going okay so that part well it's kind of simple you know we built into this an ability to start adding features so now what would be the next thing that we would want to do I think we want to do our colors we'll worry about brightness later but zero is going to be white and then one red to green three blue for cyan five magenta and six yellow and so we're going to need a lot of if statements and so let's do the first one and then I'm just going to start by copying and pasting this because I think a lot of these things will be the same so in just the color setting I don't want to mess with I don't okay so what are we gonna do we're gonna do the first color which is going to be zero which is white so I'm gonna press the zero button and see what I get up here I get zero as the command so if my comm is zero okay what do I want I want white well what would white be our bright is 255 okay G bright is 255 and be bright is 255 okay now defect okay defect when I hit power or when I hit off I want it to go to a brightness of zero and when I had power I wanted it to go to a brightness fulbright which is one but here at zero I don't want to change the brightness I want to say whatever brightness I will I so I don't want to monkey with that so do you understand the difference between the zero and the power power comes on white Fulbright but one keeps your present brightness so if I was at red and went dim dim dim dim and then went to zero I want a dim dim dim dim white okay you see I've got a pass that dimness factor between the different colors when I use the numbers so that means I don't want to change the defect when I do the numbers all right so now I think that I can take this and all these are going to be very similar so I'm going to put control V then I'm going to say what is the next one the color red for one I press one just to see in the command is did it see it I thought I saw have you little live okay one all right so now on this one if my comm is one what color did we want red that would be our bright 255 green bright zero blue bright zero so that should give me red this should go pretty quickly so control copy again we're not going to fiddle with the the dim here control V now what is the next one the next one is green I'm going to press the to button and the command is to and we set these up so you could say well you set these up you should already know them yeah but what if I had some goofy capitalization so for this case red would be zero and G would be 255 so red green blue hopefully I'm saying this right number three will be blue so I'm going to press the number three button the command is three so I will come over here and it will control the paste again and now one two I will make this three and now that's 255 0 I'm sorry for blue you want to turn red off you want to turn green off and blue would be 255 okay we have red green blue we are going through this quickly next we want cyan control V and that would be button for what is the button for command I'm going to press it just to be sure and the command is at all you are so if my command is fo you are then what do I want I want cyan cyan is kind of no red and it's kind of mixing green and it's mixing blue ok and now we want cyan magenta five is magenta so let's press five and see what we get press the five button and we get fi ve so now I will control V again and if my comm equals fi ve then cyan magenta magenta is sometimes I have trouble remembering these magenta is red and blue okay red and blue is going to make magenta and now cyan magenta the last one is yellow so yellow was the six key so I will press the six key what did it see it saw absolutely nothing I thought I saw that happy little light there but I guess I didn't okay six and you guys have kind of washed your focus here I'm sorry okay that what's that good focus okay so you've got six so if Mike on my command is equal to six then yellow would be red and green makes yellow blue has nothing to do in here all right then we're gonna write those three values okay this time I will need you to hold your breath I better have some sake okay everyone holding their breath all together now yes download hold your breath ah yes okay boom it downloaded but now the question the question is is it going to work well let's start by trying to turn it on okay I hit PWR boom it turned on let's try turning it off boom it turned off you follow the fun up here okay now let's go one it should be red giddy up it turned red okay two should be green lovely lovely change my mind I'm feeling like blue boom do you see that blue look at that we're controlling color from our little remote those are the primary colors RGB but there's also the primary color cyan magenta and yellow let's see if we can have a little cyan by pressing four lovely is that not a lovely cyan let's try magenta number five boom we have magenta we have magenta cyan magenta I think in that magenta I would like to tone blue down just a little bit I think the blue is too strong and so we can tweak those numbers a little bit later okay and then let's go to number six okay and that is a lovely yellow look at that now I'm gonna go back to to red green look at that this is working great okay now what is the one problem that I had I didn't I feel like as I'm mixing these colors that blue is too strong so if I go to five and I try to look at magenta that is too much blue in that magenta so let's come down and let's tone down the blue in the magenta and we can do that coming over here if I can get this to work okay so what was magenta that was cyan't that was button five so I'll come down to five instead of be bright of 255 I'm gonna make it like 200 okay and so now let's see if that gets a little bit better value a little bit better tone okay and let me come over where you can see it completely alright and you lost your focus again so let me see if I can give you a focus okay yeah that looks pretty good okay so let's see what just happened all right so I'm going to turn it off with a zero I'm not sure what happened while we were fooling around there okay it's off and now I'm going to turn it on with power you see the happy little light and now I'm going to turn it to five okay now oh I turned it down to 200 and now it went all the way to red hmm maybe I turned it down too much let's try making it to 40 okay it's downloading downloading downloading you get out of your way okay so now if I click five look at that it's turning just red there's no difference between that and red what if I go all the way to 254 that certainly should work right okay so let me go to five hmm houston we have a problem it is like this pin is not acting like an analog pin it's acting like a digital pin if I don't go to 55 it turns off that channel let me go back to 255 and we're gonna see blue come back like full strength so I can make blue full strength or I can make it off but it's not working for those in between values okay it's not working for those in between values did anybody else out there have this problem did anybody else out there now you see it comes back blue full blast and it's too much so how do we debug this how do we get to the bottom of it well the first thing is what we see is is that this blue pin which if I look over here this blue pin is pin 11 pin 11 is not acting like a pwm pin it's not acting like an analog out pin so first of all did we make a mistake and did we hook up to something that didn't have a squiggly well the Nano doesn't list the squiggly so let's come over here on the île egg ooh ooh no r3 and we hope that it will focus we hope that it will focus we'll give it some help here okay they're beautiful focus do you see pin 11 definitely definitely has a squiggle bite so it's supposed to act like a PWM but it is not acting like a PWM all right what can I do I think what I'm going to do is come over to the oscilloscope and what I'll do is I'll just modify this code where on the on function now what we're doing is we're debugging I want to see I think you kind of know that it's acting like a digital pin and not an analog but let's just confirm that so I'm going to come in and on power I'm just gonna set them all on half power like 150 I guess 125 would be better 125 125 125 and then I'm gonna download this and then we're gonna take a look at the scope and see it seems like pin 11 is not acting like PWM so let's download this and we will go over to the scope okay hope I don't make you dizzy but we are just gonna move the camera and we're gonna point over here at the scope and now what I'm going to do is I am setting I wonder if I have a view where you could see this both of these I think this view is about as good as you're gonna get so I'll just switch over here so you can see it so what I'm going to do is I'm connecting the ground of the oscilloscope to the ground of my circuit maybe I'll hold it up here where you can see it and now I'm going to check the red pin I'm gonna check the red pin by putting this oh man you guys really have to see this okay and we need to see what I'm doing I wish I had an extra camera okay so I've got the oscilloscope grounded to ground and now that first pin is pin six and so I'm going to plug the oscilloscope into pin 6 I believe okay and now what I'm going to do is I'm going to hit the power button PWR alright oh please PWR okay so I turned PWR on the thing came on but I am certainly not seeing any blew in that so let's come over and look at the oscilloscope and I've got the oscilloscope hooked up to what the red pin and the red pin is acting like pwn it's on half the time it's off half the time so and the red function seemed to be working now I'm going to go to G which is pin 10 and when I plug in to pin 10 it likewise is acting like PWM so pin 10 is working and pin 6 is working all right but what happens if I go to pen 11 I plug pin 11 in and it's all the way off so I'm getting nothing out of it even though I'm telling it to write at one 125 okay does that make sense what I'm saying you see I've got that command B bright is 125 but I'm getting nothing out of the oscilloscope but I am getting something out here on the green pin and I'm getting something out on the red pin so if you don't have an oscilloscope you don't really need one because you saw just by playing around just by playing around with the LED you saw that pin 11 is not giving me a PWM signal so since I connected it directly to the pin what could be going on here well the pin could be burned out maybe one thing you could do is you could go in and put in another another Arduino but usually the Arduino is not at fault usually there's something else going on okay what's one thing that we have going on over here in the software oh we've got this ir remote thing going on we've got this ir remote thing going on and that ir remote operates with an interrupt and so it's always going and interrupting the program and so even though we just say well I are remote and start sending it commands what if I are remote is messing with our pwms so in a case like this who is our friend Google is our friends so we are going to come over here and we are going to go to a Google window and I am going to type in I'm going to type in IR remote library affecting PWM doesn't that seem to be what's happening because before when we operated the RGB LED everything worked good but now it's like that Penn 11 is not responding so Arduino Uno problem with PWM function on RGB LED in infrared remote sounds like our problem let's go there and see what it says I'm having an issue controlling an RGB LED with Arduino and a remote when including the library hmm sounds like us the blue channel only works in on off instead of PWM huh sounds like us let's see what the solution is down here oh my some console provided this solution by default oh man I wish you guys could see that larger let me see if I can not give you such an eye test ok let's see what the solution was here and let me go do a different view here that you can good ok this will work I'll get further out of your way ok what is this solution on on this forum site but by default on remote library which we're using uses time or two on the atmega that's the microprocessor this timer is also used for pwn on pins 3 and 11 this means you will have to use different pwm pin for the LED alternatively you could edit the I remote library to use time or one I don't want to edit the library what this is saying is is that when you load that library it starts messing with pins three and eleven which means you shouldn't use pins three and eleven did you guys have this problem or if you did did you figure out the solution or did you just fold up like a cheap lawn chair run from the room crying like a little child go get on your xbox or start doing Instagram or snapchat or whatever and just decide you're not going to be an engineer no you've got to dig into these things how long did it take me to debug that about two or three minutes okay so what it is saying is it is saying that we cannot use pins three or pins eleven okay so what problem are we having we're running out of pins I can't use eleven I'm already using ten I'm using nan for the infrared remote I'm using six and I can't use three what does that leave one pwm pin which is pin five okay one pwm pin which is pin five now since I don't have a perfectly sized wire I am going to take this one out and I will get out of your way again I'm going to take this one out that went to pin eleven because that's a no-no and in this case I am just going to use a jumper wire so I'm going to go from the blue over - we said pin five on the Arduino so pin five on the Arduino over to the blue LED alright so now if we go back to code view what does that mean that we're gonna have to do over here on our code view that blue pin is no longer eleven the blue pin is no longer eleven the blue pin is now five okay now what we're also going to do is down here where we did that that right with the power and we wrote through as PWR here right this was the one we were monkeying with let's just see if we can get a half bright blue so I'm gonna go zero zero and then I'm just gonna look at blue to see if this will come on halfway which it wouldn't have all ago so we're going to download and remember that if statement was for the power so I'm gonna press PWR and I should see half brightness blue with PWR I hit PWR I saw the happy little light I thought I did maybe I didn't let me try it again the happy little light and PWR boom half right blue okay now let's do a really dim blue just to make sure so let's say that blue bright is 10 and we should really see it go very dim this time when we download it and then I have to press PWR again okay so we hit this and we see PWR and did this even come on this time debride oh yeah do you see that we have fixed the balloon color problem all three are now getting PWM signals so let's go back to where we were this was 255 this was 255 and this was 255 for PWR and now what we were trying to do is we didn't like our magenta we didn't like our magenta because there was too much blue and so let's go back and let's tone down that magenta magenta was pin five and so we need to look for the five in the if statement oh I got two of these things that is not good why did I put it why did I put that in there twice did you guys catch that okay I head to PWR if statements somehow all right but now let's fix the five one two three four five and here we thought be bright was too bright and said let's go to 200 and let's see if we'll get a better in magenta I'm going to download I'm not gonna hold my breath and confidence that at least it's going to download I'm not confident that I'll get the perfect magenta but I am confident that it's going to download okay it looks like it's downloaded I will hit the power button or I'm sorry y'all hit the power button it turned on PWR and then we see PWR it comes on and now what I'm going to do is click the number-5 button okay it sees that and then look at that that is a much much better magenta but I still think that it is a little bright I'm gonna turn that on down to 150 because I still see too much blue I want I want more about magenta color if that makes sense let's download it again and you just got to kind of tune this till it looks right for you and that would be a good homework is to go in look up technically what red green blue cyan magenta and yellow look like and then tune your program so let's turn it on there PWR comes on and now I will press button 5 for magenta oh that is a lovely magenta there that is really a lovely magenta I'm not sure if you're seeing it perfectly because of the camera not being exactly what real life is but that is a very very nice magenta in my in my estimation okay so now what do we have to do we got a deal with this we got a deal with this brightness thing alright now on brightness what you have to understand is you might intuitively your first thought be the way to do this is if you hit one of the like dim keys if you hit the dim key - like just subtract 15 from our bright G bright and be bright just like subtract a number down from it or if you hit up add a number to it but the problem is it's kind of like the difference between an arithmetic progression and a geometric progression your eye does not perceive brightness linearly so let me let me explain it this way if you do an analogue right of 254 and then you do an analog right of brightness of 255 your eye cannot perceive the difference between 254 and 255 but if you put in an analog right of one and then put in an analog right of 2 you can see a huge difference between 1 and 2 but not between 254 and 255 so you don't want to subtract numbers for dimming because if you do let's say you subtracted 10 from 255 to 245 you're not going to perceive a difference but when you go from 20 to 10 there's going to be an enormous difference and then from 10 to 0 you see kind of jumped over so you don't want to scale it by subtraction you want to scale it through multiplication okay so first of all let's figure out what this key is so if I press the down key the command is D in so that dim key is going to be the command D in and what we want to do is we don't want to mess with we don't want to mess with these brightness values what is it that we want to mess with this factor 1 is 100% that means let me make sure I did that right that factor 1 is 100% okay and that would be full brightness half brightness would be 0.5 10% brightness would be point so this is going to be a fraction we did it as a float okay and so you got to think of it that way so we're going to come down here and after we dealt with the colors we're going to say if my command equal equal what was it the string D in when we press that button and what do we want to do well it would be D fact is equal to D five times let's say point seven five all right and we'll check it and see can i percieve like at point seven five can I perceive that it is going down all right then what's the other one if my command equal equal and what is the command if I hit the little UP button which we said was going to be brighter I hit the little up it is yupi up so if my command is equal to up that means we need to boost that D factor in that case D fat D fact is equal to D fact times you might say one point two five but because it kind of the round off error I think you need to boost it a little bit I'm gonna say one point three all right now the other thing you have to think is you can't write a value greater than 255 now if I'm multiplying by 0.75 0.75 0.75 0.75 the worst I'll do is get to zero and zero is okay but if you're boosting it times one point three times one point three you've got to make sure that you don't go over to 55 which makes means you've got to make sure that D fact that multiplication factor never goes beyond one so if d fact is greater than one what do you want to do you want to pin it D fact equals one and this is just saying that you never let D go above one which means that your brightness values will never go above 255 does that make sense I hope so alright I think that looks pretty good let's see if we can download this all right no now what we essays now I've got this factor that I can scale the brightness is down by but I haven't done anything with it well where would we do that right here times defect so if defect is less than 1 it's going to pull down what you're writing times defect times defect ok so now the scale factor I'm calculated I'm now writing it in and if I go to red to green to blue I'm changing the colors it's gonna bring that debt scale factor that dim factor along with it ok let's download this oh did you guys see that what's the real problem real problem is we didn't hold our breath ok everyone hold your breath [Music] download download hold your breath hold your breath boom ok at least it downloaded all right now let's try this let's try this I'm gonna get the keyboard out of the way all right let's say I want it red what would I hit one okay one boom it's red oh that is much too bright let me hit the down button and see what happens see if you can perceive the change when I hit the down button dn got the command boom did you see that I saw it boom another one dn did you see that I'm dim in the light one more day and see if you can perceive it did you see that we are dimming the light okay let's see if we can bring it back see if you can perceive it coming up so I'm going to hit up yes I perceived it can you perceive it I'll go up again boom there it was I'll go up again boom there it was okay now let's try this okay I'm gonna go really really dim so I'm gonna hit dim okay yep that dimmed dim yep that dimmed okay oh that dimmed again I'm gonna take the globe off and let's let's see if we can get some focus on this I hate this blasted aggravating thing that never wants to focus okay so I'm gonna go down again let's see I'll give you a full view here this is a pretty good view here I think alright yeah so you can see I'm gonna go down again on red okay it dimmed go again it's even dimmer go again okay in in real life it is really really really getting dim very very dim one more okay one more okay I keep saying one more one more okay so that is really really really dim but now let's go to green now the trick is when I go to green it needs to stay dim so I'm gonna go to two damn green dim green okay now let's go three all right it didn't see it try it again three dim blue now let's see if I can brighten up the blue a little bit yeah did you see that brighten it up boom now let's go cyan Oh I'm gonna tone down that sigh and I'm gonna go dim yep it dimmed go again dim go again damn go again damn it's very dim cyan now we're gonna go to magenta with five okay lovely magenta now we're gonna go yellow lovely yellow I'm gonna dim it dim the yellow damn it again okay there it went damn it one more time sometimes it doesn't see that okay very dim now I'm gonna go back to two which is green and now let's see if we can bring the brightness up yep I saw it yep boom do you guys see what we have done here alright this is one I hope you guys will really leave comments did anybody did anybody do this assignment correctly without watching the video did anybody do the homework and get it right okay at least did some of you try to do it and not able to figure it out and then after watching me do it are you able to understand it the goal here was not to make an RGB LED controlled with a remote the goal was for you to learn to do something by yourself and I gave you a project where I deliberately put some roadblocks in your way to see if you could get to the bottom of it did you see how methodically we thought through this I'm trying to think what was the first problem the first problem was kind of like figuring out how to deal with this dim where you're not ever changing RGB values red green and blue values for dimming you're changing that factor and therefore that same factor could be applied to all the different colors if you were in there trying to monkey with the colors then you have one variable that you're using to change colors and changing brightness and that would be very hard to make work also if you guys figured out a way to do this different than what I did let me know okay but I'd really like to hear feedback also I hope you guys will start getting a sense of community start commenting on other people's comments and so that's one of your homeworks today your homework is leave a comment on this project and then also respond to someone else's comments so look at their comments respond to someone else's comments and start getting to know people because though you guys that have made it this far we got kind of a core group of people that are going through these lessons and start getting to know each other develop a little bit of a sense of community okay Paul McWhorter from top tech boy comm I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 33,210
Rating: undefined out of 5
Keywords: RGB, LED, Remote Control, IR, Dimmable
Id: 2tphX8scoM8
Channel Id: undefined
Length: 70min 18sec (4218 seconds)
Published: Tue Jun 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.