Beginner needing help

I am a year 10 highschool student and haven't ever used Arduino until a couple months ago. I found a RGB code online and coped it into IDE, then I changed it so that the LED's would flash red and blue fast. That worked, now i have been trying to make it so that the LED's flash different colors instead of changing from red to blue at the same time, like this diagram.

Im using an Arduino Uno Rev 3. The LED's are 4 KY-016 LED Modules and 1 KY-009 LED Module.

Here's what I've got so far, keeps giving me the error "Expected unqualified-id before '{' token".

Again this is my first project so go easy on me, thanks for any help :slight_smile:

int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
int red_light_p= 6;
int green_light_p = 5;
int blue_light_p = 3;

void setup() {
  pinMode(red_light_pin, OUTPUT);
  pinMode(green_light_pin, OUTPUT);
  pinMode(blue_light_pin, OUTPUT);
  pinMode(red_light_p, OUTPUT);
  pinMode(green_light_p, OUTPUT);
  pinMode(blue_light_p, OUTPUT);
}
void loop() {
  RGB_color(255, 0, 0); // Red
  delay(400);
  RGB_color(0, 0, 255); // Blue
  delay(400);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value){ 
}
void RGB_colo(int red_light_v, int green_light_v, int blue_light_v){ 
}
{
  analogWrite(red_light_pin, red_light_value);
  analogWrite(green_light_pin, green_light_value);
  analogWrite(blue_light_pin, blue_light_value);
  analogWrite(red_light_p, red_light_v);
  analogWrite(green_light_p, green_light_v);
  analogWrite(blue_light_p, blue_light_v);
}
1 Like

All of the following code seems like it was accidentally included as a duplicate.

}
void RGB_colo(int red_light_v, int green_light_v, int blue_light_v){ 
}
{

There are other errors, but removing those lines will make it easier to identify and correct them.

int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;

void setup() {
  pinMode(red_light_pin, OUTPUT);
  pinMode(green_light_pin, OUTPUT);
  pinMode(blue_light_pin, OUTPUT);
}
void loop() {
  RGB_color(255, 0, 0); // Red
  delay(400);
  RGB_color(0, 0, 255); // Blue
  delay(400);
}
void RGB_color(int red_light_value, int green_light_value, int blue_light_value){ 
}
{
  analogWrite(red_light_pin, red_light_value);
  analogWrite(green_light_pin, green_light_value);
  analogWrite(blue_light_pin, blue_light_value);
}

This was the code that worked where it changed the lights from red to blue at the same time. I tried just copying it and changing the names of the variables but it didnt work. Im very confused on how to proceed. I want the lights on number 11, 10 and 9 to change to red when numbers 3, 5, and 6 change to blue, and vice versa. Any idea on how to do that? Thanks :slight_smile:

Hi pleo,

welcome to the arduino-user-forum,
a like for posting code as a code-section. Well done.

As you have experienced with your attempt to modify the code with only a small knowledge about programming this does not work.

There are some fundamental basic rules about syntax and about programming that you should learn. Without a basic knowledge your communication in the forum would be "remotely instructed keyboard-typing without understanding anything"

I don't know what a learning-type you are. You can
Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

As a next learning-step

I want to support in a way that fits to your knowledge-level
please post what you think / what you assume what these lines of code do

  pinMode(red_light_pin, OUTPUT);
  pinMode(green_light_pin, OUTPUT);
  pinMode(blue_light_pin, OUTPUT);
  pinMode(red_light_p, OUTPUT);
  pinMode(green_light_p, OUTPUT);
  pinMode(blue_light_p, OUTPUT);

please post what you think / what you assume what these lines of code do

  RGB_color(255, 0, 0); // Red
  RGB_color(0, 0, 255); // Blue

best regards Stefan

This means that your braces { and } do not matched up.

Each function must start with a { and end with a }

You can not define a function inside another function.

This is an international forum and this will mean little to any non UK resident. Even if you live in the UK it will mean nothing to people over 50 due to when this numbering system was adopted.
I asked my wife, who was a teacher, how old you would be and she said about 15 about to take your GCSE exam. In my day that would be known as a forth form student, which would mean nothing to you, would it? Not criticising just trying to increase your general education. :smiley:

Okay thank you for the help Grumpt_Mike.
I am also Australian haha, but thank you.

1 Like

I think the pinMode section is to define what name is what.
I also thing the RGB_color section is controlling the color of the lights.

I will definitely have a look at that course to learn a bit more.

section that defines variables of type int with self-explaining names

defining the mode of the IO-pins to work as output
"pour electrones from the microcontroller towards the LEDs"

The opposite would be to work as input
"collect electrons into the microcontroller"

basic function: light up RGB-LED where the variables

red_light_value
green_light_value
blue_light_value

hold a number that repesents intensity

based on a principle called PWM pulse-width-modulation

best regards Stefan

OK, so how old are you then?

The important thing is to delete everything that is posted in reply #2 and then see what you get.