Arduino Uno R4 WiFi LESSON 19: Mixing Colors with an RGB LED

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Paul mcarter with toptechboy do.com and we're here today with episode number 19 in our incredible new tutorial Series where you're learning how to think like an engineer using the Arduino Uno R4 WiFi what I will need you to do is pour yourself a nice strong glass of ice cold coffee that is straight up black coffee pour it over ice no sugar no sweeteners none needed and as you're pouring your coffee as always I want to give a shout out to our friends over at sunfounder sunfounder is actually sponsoring this most excellent series of video lessons and in this class we will be using the sunfounder elite Explorer kit now hopefully most of you guys already have your gear but if you don't look down in the description there is a link over to Amazon you can hop h on over there and pick your kid up and believe me your life and my life are going to be a whole lot easier if we are working on identical Hardware but enough of this Shameless self-promotion let's jump in and talk about what I am going to teach you today and what I'm going to teach you is I'm going to well basically what I'm going to be showing you is I'm going to be showing you my solution to the homework assignment that I gave you in lesson number 18 so I'm at must ask were you successful in doing the homework if you were successful leave a comment down below I Am Legend double just bump if you are not successful leave a comment down below I fold it up like a cheap Walmart lawn chair man I hope you guys were successful because it really was just kind of combining the things that I'd already taught in earlier lessons to do a new project and what I'm trying to do is on these homeworks I'm trying to reinforce for the earlier learning so that you don't just see it once but you see it and you begin to use it it begins to become part of your toolbox so I hope you guys were able to do it now what I showed you was with an RGB a red green blue LED I showed you how you could turn it red you could turn it green you could turn it blue but in the homework assignment I told you to give the user an option of red green blue cyan magenta yellow and then orange white and then I'm going to go ahead and throw in on my solution off to turn the thing off now hopefully hopefully you weren't looking for an eight-legged LED that had a cyan magenta and yellow hopefully you made the connection that the way you were going to get those other colors was to mix the Reds the greens and the blues to get these other colors so hopefully you guys caught on to that but this is going to be kind of a fun little lesson so let me get out of your way let me enjoy a sip of coffee and let's come over to our overhead view now I showed you in the last lesson how to hook up the RGB LED so I'm not going to take you through that step by step but I just want you to see that this second leg the second leg on the B on the Downs side it is the long leg the second leg over the second leg right here that is the long leg so make sure that you plug it in the same way that I have it plugged in and if you plug it in that way then this will be the r the red channel the next one again is ground and then this one will be the green Channel and this one will be the blue channel so I've got red ground green blue now the red the green and the blue need a what they need a current limiting resistor so I have 1,000 ohm resistors that a 1,000 ohm resistor that goes from the red leg across the trench and then I connect it to the red wire to our friend Mr pin 9 then the Green Leg of the LED goes to this th Ohm resistor jumps the trench it goes to the green wire to our friend Mr pin 10 and then the blue leg of the LED goes across the 1 ohm resistor it goes through the 1000 Ohm resistor to the blue wire which goes to our friend uh pin 11 so we're using pin 9 pin 10 and pin 11 and so that should be familiar to you the one other thing I think I should show you here is this second pin this long leg what I have it connected to is I have it connected to this bottom rail over here and then I make this entire rail this entire strip here I make a ground by taking this wire and running it back to one of the ground connections on the Earth Arduino and so I went pretty fast there if I went too fast if I went too fast for you go back and watch lesson number 18 because I really explained it in quite a lot of detail there so I just I wanted to kind of just review it but not spend a lot of time on it so I do think that we're ready to start coding and so we're going to come over here and I got to get this window a better proportion here a more Adept YouTuber would have had that ready already but we'll try to power on through and get it uh get it going okay so what I need you to do is open up your Arduino IDE we're always going to start with bare minimum so we go to file examples basic and open up bare minimum and then we always want to make sure our Arduino is connected so I'm going to go to tools port and then you can see that my Arduino is on com 5 so I select com 5 you'll probably be on a different com but wherever your Arduino shows up select that one okay so that looks good and now we're going to come up here and we're going to start coding we're going to start coding but I'm going to have a little jet fuel first I'm going to go a little faster through this first part because a lot of it is similar to what we did last week so the first thing is I want to set up my variables for my pin and so I'll say I have an INT variable for red pin and that's going to be equal to what what did I say the red wire was connected to our friend Mr pin n okay like that now I'm going to do int green pin and that was what pin 10 do you see how I like to do things in order I like to do everything red green blue red wire green wire blue wire and then I need to red green blue I like to do everything in the same order and then the coding just kind of clicks it just kind of clicks okay now I'm going to do int blue pin it clicks even more if I don't talk so much and that's going to be pin 11 and then what I'm going to do is I'm going to have a b rate BR and that is is going to be equal to 115200 just because we can and then remember if I set the BR here to 115200 down here in our friendly serial monitor right down here I'm going to go ahead and turn that serial monitor on I should make sure that this is 115200 here and just a reminder this has to be on no line ending or you're going to get all types of wacko results and so man in that first Arduino class I did I the most common comment I got and I got thousands of them it doesn't work it doesn't work I did exactly what you did yeah but you didn't listen to me when I said set your serial monitor to no line ending okay now we're going to come up to our void setup we're going to go inside the void void setup which means what is inside the void setup it means between the open curly and the closed curly this curly opens the void setup this curly closes the void setup we are talking to the serial monitor so what do we need to do we need to start at serial. and what did we say 1152 no no no don't type that number in there use your variable BR like that okay now we also have three pins so we need to do what three pin modes and so we're going to go pin mode which pin red pin and it is an output okay we're going to do a pin mode which plant pin green pin and it is a what it is an out output all uppercase like that okay then we're going to do a pin mode and then we're going to do what blue pin like that output this is going fast now we're going to do what a pin pin mode and then what si si cyan pin out no no no you don't have a cyan pin you got a red CR pin a green pen and a blue pen you're going to have to figure out how to get that cyan but you're not going to do it through a cyan pin right so now I have that all set up that looks pretty good colon colon colon all uppercase red green blue just glancing over it okay that looks good okay now what do we want to get we want to get from the user what color they want okay what color does the user want what color does the user want so if I want to get input from the user I have to do what three things ask wait read and so I'm going to ask and that reminds me I should probably up here set up a prompt okay so I'm going to have a string and that is going to be my prom and that's going to be the string and side of quotes enter your de desired color please okay like that and then also I'm going to need a variable to put what they put in there I got to have a variable to hold the color they want and so I'm going to make that a stringa and that's going to be user color I don't like user color is kind of is kind of long I'll use user color that's all right user color and I'm not going to set that anything because we'll get that from who from the user all right now we need to ask weit read how do we ask with the print statement serial do print Ln because we want to go to the next line print Ln what my promp like that okay now what do we do we've asked now what do we do we wait why [Music] serial. available equals 0 then what do we do we open the curly and then we close the curly so what does this do this is going to wait tell me what you don't like tell me what you don't like the first thing that you don't like is the conditionals always need to be inside of parentheses okay and so now I the conditional whether it's an if statement or a while loop or whatever the conditional always goes inside the parentheses now tell me what else you don't like if you're checking a conditional you never say equal you always say what equal equal so now everything's perfect right everything's perfect no what else serial. available that has a what that has an open close see see I like giving you guys homework assignments because you got to get comfortable with those things did you see how right that was when I said while like I did it originally it really looked right but there were what in one little bit of code something that really looked right had three pretty big errors now how long does it wait it waits as long as it takes and then when something is on the serial monitor then it is going to read it it is going to read it so I come down here and I say user color is equal to serial. parse in no no no it's not an INT it's a what serial. reading read stringa and then an open close like that now these crazy guys out there some of you old guys it's like you leave your cap blocks on and some of you young guys you do this crazy every other letter is uppercase B I don't know what you guys are going to do so whatever you do I'm going to convert it to lowercase and so I am going to do that with our friend here with our friend I'm trying to get this all all lined up here what is it it is user okay user color. t lower case and notice the L is uppercase the C is uppercase you got to do it perfectly we give it the old open close parenthesis and we bring it on Home with our friend the semi semicolon so user color becomes user color to lowercase now it doesn't matter what kind of nonsense you're doing with uppercase lowercase I'll be able to get these if statements to work correctly so now what's the first thing we're going to look for is we're going to look for a red and so I say if and then I say if user color is equal to the string red then what do I do I open and close my curly no no no what did I do I did it again what what do this has to be in a parentheses because it is a conditional okay and what did I do here I just made user color equal to Red if I want to see if it's red I need to do the what the equal equal now what would I do here well I could do digital wrs but I think you're going to see it's really better to do analog rights here and that way we can tweak our values if we want to adjust our colors a little bit so I'm going to do analog write who am I going to write to Red pen and where am I going to put him 2 55 like that now you could go put variables up there but in this case I'm just going to keep going it's it's sort of like it gets a little tedious if I have a whole bunch of different uh like you know red bright green bright blue bright I'm just going to go with numbers here I'm going to claim instructor prerogative on that one even though I tell you that's bad programming and I'm going to what I better I don't know what last guy that used this I don't know what he put he might have let the thing blue so I better turn the other ones off so red pin green pin is going to be zero okay like that and now analog right and then I'm going to say red green blue pin and that is going to be zero as well all right I should be able to run this already and I just want to test it for Red because what I'm going to do is I'm going to take that code and I'm going to copy and paste it for green blue cyan magenta yellow and then orange and then white and then off I'm going to copy it for all of those so I kind of want to see if it runs before I you know before I do all that copying and pasting so let's run this thing and let's see ah a what is that it hates me what is that it hates me string color string user color that sure looks right string the S is uppercase user color that's right semicolon that's right why is it giving me an error on that string command well maybe it is the line before where we forgot who our friend friend Mr semicolon so let's try again at least that wouldn't have been one that I would have copied and pasted what is this okay so remember when I did this I showed you three errors I was going to see if you were paying attention and we're going to show me the fourth error what is the fourth error it should be uppercase like that okay but you see when you do that then you guys leave a comment and you say I did exactly what you did and it did didn't work no if you did exactly what I did you would get exactly the same result that I was getting if you're not getting the result that I got then you made a mistake and the number one most important thing in being an effective troubleshooter is realizing it it if it doesn't work it's because you made a mistake and you know what I used to tell my students when I taught them in person they'd say you know my program's not working and what I would tell them is it is doing exactly what you told it to do and so when they said my program isn't working I would say well what's it doing correct answer is well it's doing exactly what I told it to do well then go tell it the right thing to do but you've got to really you've got to mentally kind of come to grips with it looks so right but you just gota you got to say it looks right but there's a mistake in there I got to go in there and find it and once you get that mindset then you can do troubleshooting a lot better let's try it again okay no ugly little orange no ugly little orange and it is downloading and Boom at least we got the errors out of there so let's come back to our serial monitor now we didn't have it open so I'm going to have to press the button to run it again now I get the prompt and then I'm just going to T I'm just going to type in red and boom okay so at least I know that snippet of code works and so what we're going to do is I'm going to take this blank space out and so I'm going to get the close curly that closes the Clause the open curly that opens it and go all the way to the if statement I'm going to copy that and then I always like to leave kind of like blank lines between my chunks of code and I'm going to paste it but this time what do we want we want green like that and then for green red would be what zero and green would be 255 like that okay so we've done red and green now let's come in and we are going to do red green and blue like that and for blue certainly you don't want red on you certainly don't want red on and in fact you don't want green on but what do you want you want blue on and you want it how far on all the way man we want it all the way on at 255 so we've done red green blue now now the Moment of Truth we are going to come to what we're coming to cyan and San is a mixture of what of green and blue cyan could also be considered like Aqua or turquoise and so for that what I'm going to do is I'm going to put the green at 255 I'm going to put the blue at 255 now I will say when we look at that we want want to see if it's a good cyan because you know the red the green and the blue LED they're sort of different materials and some of them for the same voltage for the same output level will have different brightnesses and so just turning them both full on does not necessarily give you really that perfect uh cyan so you might need to adjust those numbers a little bit but we'll only know that after we look at it so now what do we do we do our friend cyan and then h is Buddy magenta okay and magenta likewise is going to be red and blue so we're going to go 255 like that so that's our friend magenta is a mixture of red and blue hopefully you guys figured this out okay cyan magenta and now we are to The elusive yellow sometimes yellow you've got to play with a little bit yellow seems to be one that you a lot of times have to tweak but the yellow is going to be red and what green 25 like that okay now what else we also said beside yellow we wanted what we wanted orange orang orange orange like that and orange is also a mixture of red and green but really you want less green and you want more red so you want to turn that green down because because like orange is on the red side of yellow so you want more red and you want less green and so I'm going to put instead of 255 I'm going to put like 150 and we'll see where it goes from there we got to look at it we got to dial it in we got to adjust it we got to F tune it okay we got to F tune it so now I've done cyan magenta yellow and I've done orange well what do we want we want white now so I'm going to do this and then white is really what is white it's the combination of red and green and blue blue and so we can get pretty close if we go 255 255 and 255 we'll turn them all on and we should get something close to White and then what else do I want to do I want to do an overall over an out so I'm going to say off off or F that's not good off and then off is going to be two it's going to be zero 0 0 so they should be all off then let's think if there's anything else that we need to think about here I think that really looks pretty good now we probably are going to need to tweak those values a little bit and so what I'm going to do is I'm going to come in here and run it have a little sip of my Go Juice are you guys drinking your coffee are you still drinking those sugary worthless kill you kill you drinks straight up CL coffee no sugar you don't need any sugar in your beverages okay so now it looks like I got a uh it looks like I got a prompt so let's go ahead and say red and see if it doesn't work then I just know I need to reset it but I think that is my prompt boom look at that red now what I want to show you is I've got this diffuser and that really is a really good red and it just helps you see it a little bit better I wish I had a little stand so I wouldn't have to just keep it holding it on there okay red green boom let's see what happens look at that now that is a beautiful lovely perfect spectacular saturated wonderful green okay now what blue like that blue okay and look at that magnificent marvelous blue a lovely lovely blue okay now red green blue now what this is the moment of truth sanne and what I'm going to try to hold this ah I'm going to try to hold this as it changes and I want you to see that the blue kind of goes more into you watch the green come into it okay now do you see that uh do you see that that now it is that Aqua turquoise lovely turquoise is one of my favorite colors that Aqua yeah that's one of my favorite colors s so we've done red green blue cyan now we're going to go to magenta I really like magenta too magenta is another really nice color look at that magenta is kind of that purple color we've got that cyan magenta and now the Moment of Truth yellow is always the hard one okay now when I look at this the problem is that really has too much green in it you see when I'm looking at this I'm getting a hint of yellow but the green is way way too strong and so now I'm going to come up here and which one was that one that was yellow and so on the yellow I'm going to take I'm going to take that 255 down to 150 okay and now if if that was too green then probably then probably orange was two green too and so I'm going to take that down to 50 so orange is going to be 255 red and then green I've got to take down because green green on this on this particular LED green is the bully green is overwhelming everything else so we're going to choke him down put him in his place okay yeah you think you think you can bully the other colors we'll turn you down to 50 if that doesn't work you're on your way to an even lower number Mister okay so here we go all right and here we come to Yellow like that okay now that my friend is yellow that is an absolutely perfect yellow well done well done but now the Moment of Truth orange I worry that maybe I beat up on green too much maybe I was too hard on green but let's see we'll see here I mean yeah but let's see oh man that is let's try it again make sure I got it or rrange like that yeah that is a good orange but I'm going to turn it down a little bit more dare I go to 25 dare I go to 25 let's see and you guys looking at yours in person your numbers might not be exactly the same as mine it might depend a little bit on the LED but I'm going to go or orango G orange like that oh yeah you see that is not red that is not red that really is orange so on this led where I started like up near 255 I had to really Hammer the green I had to hammer the Green in order to get that orange okay now still we're going to look at the White and the white that is really a pretty close to White there's maybe a little bit too much green in there so just like on those other ones uh let's see if I turn that green down to maybe 1 15 let's see if I get a little bit better white if I do [Music] that okay we're going to go white like that okay guys that really is that really is a better white and if I get it there right like that that really is a better white now this is acting a little bit like a lens and you can see that it's collecting green and red over at the corners but if you get it just right you can see that it's mixing to White and that looks pretty darn good okay guys so we've learned some stuff today we've reviewed the things that we've learned in the first 18 lessons and then what you learned how to do today is you learned how to mix colors now this is your home homework assignment for next week this is your homework assignment for next week what I want you to do I was distracted by something I thought I saw out the window but back to the homework this is your homework assignment leave your RGB LED hooked up and what I want you to do is I want you to flash it with this sequence red green blue so pretty quick just go red green blue and then wait like a second so it's going to go red green blue it's going to wait a a second and then red green blue wait about a second and then I want you to do that exactly I want you to do that exactly 25 times you're going to go red green blue and then you're going to wait a second red green blue wait a second and you're going to do that 25 different times and then you're going to stop okay now this sounds easy but then maybe there's going to be some things you're going to have to think a little bit about because after you do it 25 times what do I want you to do I want you to stop okay after you do it 25 times I want you to stop all right and so that's your homework assignment for next week now what I need you to do is make a short video like and by short I mean 30 seconds a minute not more than a couple of minutes where you show the code and then you show the circuit and you show your program working where you can show that it's doing what we ask you to do and then in your homework video when you post it to YouTube guys don't do the you YouTube shorts make just a real little YouTube video it's hard because the shorts you can't comment on I can't comment on your short but if you just do a normal a normal YouTube video and then in your description link back to my uh my uh lesson here and then on this lesson in the comments you link over to your homework solution and I can hop on over there and take a look at it and comment on it okay guys I hope you're having as much fun taking this class as I am making the lesson since as always I want to give a big thank you to you guys who are standing with me on patreon your support and your encouragement is what's keeping me in the game here you can also help me with a thumbs up or leaving a comment down below make sure you subscribe to the channel when you do ring that Bell so that you'll get notification when future lessons drop and most importantly share this video with other people because the world needs more people thinking like an engineer and fewer people sitting around watching silly cat videos Paul mcarter with toptechboy decom I will talk to you guys [Music] later
Info
Channel: Paul McWhorter
Views: 2,361
Rating: undefined out of 5
Keywords: STEM, LiveStream, TopTechBoy
Id: YniHyGypG9w
Channel Id: undefined
Length: 31min 10sec (1870 seconds)
Published: Thu May 30 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.