Errors that I don't understand

I have a lot of errors in my variable naming. Is there something wrong with my code? What should I do if I want to make it work?

int TurnAllOn =
{
digitalWrite(RedOne, HIGH)
digitalWrite(YellowOne, HIGH)
}

The RedOne and YellowOne are defined pins.

Please post your full sketch. If possible, you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's OK to add it as an attachment. After clicking the "Reply" button, you will see an "Attachments and other settings" link.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the forum toolbar).

int TurnAllOn =  
{
digitalWrite(RedOne, HIGH)
digitalWrite(YellowOne, HIGH)
}

The Arduino IDE is packed with programming examples.

None of them look anything like that.

Arduino functions.

OK here is the whole code. And I have used Auto Format.

void setup() {
#define RedOne 23
#define YellowOne 24
  int Tone =
  {
    void loop{
      digitalWrite(RedOne, HIGH);
      digitalWrite(YellowOne, LOW);
      delay;
      digitalWrite(RedOne, LOW);
      digitalWrite(YellowOne, HIGH);
    }
  }
}

}

void loop() {

}
  int Tone =
  {
    void loop{

What's that?

You appear to have two definitions of a function called loop.

Didn't know you can use #define inside a function.

Hi,
Welcome to the Forum.
I have edited your code t o hopefully help you understand the structure of the Arduino IDE and C++.

#define RedOne 23      //define the Red pin
#define YellowOne 24   //define the Yellow pin
int Tone;              //establish an integer variable Tone
void setup()
{
  pinMode(RedOne, OUTPUT);      //set pin 23 as an output
  pinMode(YellowOne, OUTPUT);   //set pin 24 as an output
}


void loop()
{
  digitalWrite(RedOne, HIGH);    //Red ON
  digitalWrite(YellowOne, LOW);  //Yellow OFF
  delay(500);                    //Pause for 500ms
  digitalWrite(RedOne, LOW);     //Red OFF
  digitalWrite(YellowOne, HIGH); //Yellow ON
  delay(500);                    //Pause for 500ms
}

I'm not sure what model Arduino you are using. possibly a Mega, for which it should compile.
I have commented the statement lines to help.

Tom... :slight_smile:

wvmarle:
Didn't know you can use #define inside a function.

You can use one just about anywhere.

Whether or not you should

AWOL:
You can use one just about anywhere.

Whether or not you should

Probably, would it be global if it was in setup or loop????
Tom..... :slight_smile:

Thank you Tom. And yes I am using Mega 2560.

But I have another question, can I do this?

#define RedOne 23      //define the Red pin
#define YellowOne 24   //define the Yellow pin
void setup()
{
  pinMode(RedOne, OUTPUT);      //set pin 23 as an output
  pinMode(YellowOne, OUTPUT);   //set pin 24 as an output
}
int Tone;              //establish an integer variable Tone
void loop()
{
  digitalWrite(RedOne, HIGH);    //Red ON
  digitalWrite(YellowOne, LOW);  //Yellow OFF
  delay(500);                    //Pause for 500ms
  digitalWrite(RedOne, LOW);     //Red OFF
  digitalWrite(YellowOne, HIGH); //Yellow ON
  delay(500);                    //Pause for 500ms
}

Is it the same? I am setting RedOne and YellowOne as output outside the variable instead of inside.

I am setting RedOne and YellowOne as output outside the variable instead of inside.

That sentence makes little or no sense.

What I mean is that I am setting RedOne and YellowOne as output. But I can set it as output inside the variable like Tom said or I can set it as output in the set up as I did.

What do you mean by "inside the variable"?

A variable is just a named box to hold a value.

omarico13:
Thank you Tom. And yes I am using Mega 2560.

But I have another question, can I do this?

#define RedOne 23      //define the Red pin

#define YellowOne 24   //define the Yellow pin
void setup()
{
 pinMode(RedOne, OUTPUT);      //set pin 23 as an output
 pinMode(YellowOne, OUTPUT);   //set pin 24 as an output
}
int Tone;              //establish an integer variable Tone
void loop()
{
 digitalWrite(RedOne, HIGH);    //Red ON
 digitalWrite(YellowOne, LOW);  //Yellow OFF
 delay(500);                    //Pause for 500ms
 digitalWrite(RedOne, LOW);     //Red OFF
 digitalWrite(YellowOne, HIGH); //Yellow ON
 delay(500);                    //Pause for 500ms
}



Is it the same? I am setting RedOne and YellowOne as output outside the variable instead of inside.

I think we have a translation problem.
I think you mean to say.

Is it the same? I am setting RedOne and YellowOne as output before establishing the variable Tone instead of after.

The only time that would matter I would think is if you used the variable in the void setup() function.

But why would you want to do that, it is common practice to declare all global variables before the void setup(), I see no advantage.
Tom.. :slight_smile: