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).
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.
#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.
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.
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..