Getting started with the Elegoo Mega 2560, Lesson 4 RGB LED

Hello everyone. Back when I was a kid, I had one of the fancy Radio Shack 60-in-1 electronics kits. I had a blast with that thing. Now that I'm a lot older, I saw this Elegoo kit on Amazon and bought it, hoping I could teach myself about Arduino.

I'm okay from the electrical side of it, as in I can reference everything and figure out how it works. But I'm apparently very deficient on the programming side. The ONLY experience I have with this is the documentation which came with the kit. And from what I can tell, it is very poorly written for someone with zero previous experience. I learn best by taking examples and taking them apart and reverse engineering them, to figure out what does what.

So, I have gone through the documentation that came with this kit and am now on Lesson 4, trying to figure out the software to blink and RGB LED different colors. I have everything wired up correctly, I just need the sample program so that I can tinker with it.

They do give some info in the documentation. I'll copy and paste it here and hope that someone will be kind enough to actually write it out for me, so that I can see what is missing. Thank you for any help! And I apologize if I posted this incorrectly. I read the "how to" sections here, but not sure I'm completely understanding all of it.

Alex

"Code
Our code will use FOR loops to cycle through the colors. The first FOR loop will go from RED to GREEN.
The second FOR loop will go from GREEN to BLUE.
The last FOR loop will go from BLUE to RED.
Try the sketch out and then we will dissect it in some detail......
The sketch starts by specifying which pins are going to be used for each of the colors:

[/code]// Define Pins
#define RED 3
#define GREEN 5
#define BLUE 6

The next step is to write the 'setup' function. As we have learnt in earlier lessons, the
setup function runs just once after the Arduino has reset. In this case, all it has to do is define the three pins we are using as being outputs.

void setup()
{
pinMode(RED, OUTPUT); 
pinMode(GREEN, OUTPUT); 
pinMode(BLUE, OUTPUT); 
digitalWrite(RED, HIGH); 
digitalWrite(GREEN, HIGH); 
digitalWrite(BLUE, HIGH);
}

Before we take a look at the 'loop' function, lets look at the last function in the sketch.
The define variables

[code]int redValue;
int greenValue;
int blueValue;
analogWrite(RED, 255 - redValue);

This function takes three arguments, one for the brightness of the red, green and blue LEDs. In each case the number will be in the range 0 to 255, where 0 means off and 255 means maximum brightness. The function then calls 'analogWrite' to set the brightness of each LED.
If you look at the 'loop' function you can see that we are setting the amount of red, green and blue light that we want to display and then pausing for a second before moving on to the next color.

#define delayTime 10 // fading time between colors
delay(delayTime);

Try adding a few colors of your own to the sketch and watch the effect on your LED.

I learn best by taking examples and taking them apart and reverse engineering them, to figure out what does what.

There are dozens of examples that come with the IDE that let you do just that.

It's hard to read your post with the misplaced code tags. Edit your post. Remove all the [ code ] and [ /code ] stuff (the spaces won't be there). Then, select a bit of code and press the </> icon to put that bit of code in code tags.

If you use the IDE to create a new sketch, it will provide the surrounding code for the "setup" and "loop" structure that the instructions refer to. Just copy and paste into the appropriate spots, and it will work.

I made the same purchase so exactly understand the confusion. The Elegoo tutorial PDF says: "please open the program in the code folder- Lesson 4 RGB LED, and click UPLOAD...". And then you can't find anything named that.

This is basically the same tutorial lesson with some constants and variable named slightly differently:

This may not help the original poster at this point, but perhaps will help someone else like me who came across this thread because of the same issue.

Yes, the description in the tutorial is confusing, and I've found this thread before I managed to find the code.

The code for all the lessons is in the bundle you can download from elegoo.com, and in my case it is under:

"Elegoo The Most Complete Starter Kit for MEGA V1.0.17.8.3\English\code"

That's where you can find "Lesson 4 RGB LED" among others.

IronKolobok your link worked like a dream. This company with the starter kit definitely needs some quality control! Took them 2 months to get the documentation to me after I bought the kit off of Amazon.