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.