CODE:
const byte blue = 9;
const byte red = 10;
const byte green = 11;
void setup() {
// put your setup code here, to run once:
pinMode(blue, OUTPUT);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(blue, random(0, 256));
analogWrite(red, random(0, 256));
analogWrite(green, random(0, 256));
delay(500);
}
Are the current limiting resistors for the LEDs on the little PC board? If not, where are they?
Please edit & post your code properly, or this can go to the project gallery!
Read the forum guidelines to see how to properly post code.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Hello
You shall extend your "RGB LED Beginner Tutorial" with this smart and small solution for "Random Colours Every 2 Seconds".
constexpr byte LEDs[] {10,11,12};
void setup() {
for (auto LED : LEDs) pinMode(LED, OUTPUT);
}
void loop () {for (auto LED : LEDs) analogWrite(LED, random(0,256)); delay(2000);}
Yes, all the resistors are already wired on the pc board.
Thank you very much, I fixed the code. ![]()
Done, Thank you for the warning.
It's a great idea, but I try to leave the arrays and "for" statement statements out of the beginner tutorials.
Beginner for C++ ![]()
yeah but this is beginner arduino tutorial
Thanks for the info ![]()
Np, thank you for watching ![]()
Your code is too long ![]()
Longer codes are easier to understand for beginners in my opinion, but I appreciate your feedback.