Sketch test help please

Can some one please test compile this..
As keep getting exit status 1
redefinition of 'void setup()' Tried different versions of IDE
Thanks in advance

int led_1 = 9; // the PWM pin the LED is attached to
int led_2 = 10;
int brightness_1 = 0; // how bright the LED is
int brightness_2 = 100;

int fadeAmount_1 = 5; // how many points to fade the LED by
int fadeAmount_2 = 5;

void setup() {
pinMode(led_1, OUTPUT);
pinMode(led_2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led_1, brightness_1);
analogWrite(led_2, brightness_2);

// change the brightness for next time through the loop:
brightness_1 = brightness_1 + fadeAmount_1;
brightness_2 = brightness_2 + fadeAmount_2;
// reverse the direction of the fading at the ends of the fade:
if (brightness_1 == 0 || brightness_1 == 255) {
fadeAmount_1 = -fadeAmount_1;
}else if (brightness_2 == 0 || brightness_2 == 255) {
fadeAmount_2 = -fadeAmount_2;
}
// wait for 90 milliseconds to see the dimming effect
delay(30);
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use [color = red]code tags[/color] (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

How many tabs have you got open in the IDE ?

Please post the full error message using code tags when you do

1 Like

Hi,
What model Arduino is the code for?
Did you write this code or get it from another source?

Thanks.. Tom. :smiley: :+1: :coffee: :australia:

Sorry total new, at this. A friend done this a while back, but the file was over written, managed to find what i think was a copy, but get the error. Will repost, thanks again

int led_1 = 9; // the PWM pin the LED is attached to
int led_2 = 10;
int brightness_1 = 0; // how bright the LED is
int brightness_2 = 100;

int fadeAmount_1 = 5; // how many points to fade the LED by
int fadeAmount_2 = 5;

void setup() {
pinMode(led_1, OUTPUT);
pinMode(led_2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led_1, brightness_1);
analogWrite(led_2, brightness_2);

// change the brightness for next time through the loop:
brightness_1 = brightness_1 + fadeAmount_1;
brightness_2 = brightness_2 + fadeAmount_2;
// reverse the direction of the fading at the ends of the fade:
if (brightness_1 == 0 || brightness_1 == 255) {
fadeAmount_1 = -fadeAmount_1;
}else if (brightness_2 == 0 || brightness_2 == 255) {
fadeAmount_2 = -fadeAmount_2;
}
// wait for 90 milliseconds to see the dimming effect
delay(30);
}

type or paste code here

Hi,

int led_1 = 9;  // the PWM pin the LED is attached to
int led_2 = 10;
int brightness_1 = 0;  // how bright the LED is
int brightness_2 = 100;

int fadeAmount_1 = 5;  // how many points to fade the LED by
int fadeAmount_2 = 5;

void setup() {
  pinMode(led_1, OUTPUT);
  pinMode(led_2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led_1, brightness_1);
  analogWrite(led_2, brightness_2);

  // change the brightness for next time through the loop:
  brightness_1 = brightness_1 + fadeAmount_1;
  brightness_2 = brightness_2 + fadeAmount_2;
  // reverse the direction of the fading at the ends of the fade:
  if (brightness_1 == 0 || brightness_1 == 255) {
    fadeAmount_1 = -fadeAmount_1;
  } else if (brightness_2 == 0 || brightness_2 == 255) {
    fadeAmount_2 = -fadeAmount_2;
  }
  // wait for 90 milliseconds to see the dimming effect
  delay(30);
}

It compiles for me for a UNO on 2.3.2 IDE.

I copied it to notebook++, then selected and copied it to the IDE.
Your copy may have some hidden characters, copying to notebook may wash them away.

The unwashed still compiled okay in 1.8.19 and 2.3.2

Tom.. :smiley: :+1: :coffee: :australia:

Make sure you do not have any extra copies of the sketch in the sketch folder.

Hey much appreciation for testing thank you so much. Strange, tried latest version, of IDE and 1.8.1, have 4 copies with different names, same error. Thanks again

If you have something like

  • mySketch
    • mySketch.ino
    • backup.ino
    • other.ino
    • fourth.ino

and more than one of those ino files has a setup() function, you will get the redefinition error.

Please post your full error message (and don't forget the code tags).

1 Like

As previously asked

OMG Legend thank you, had 4 copies in same folder, moved them out, now compiles :slight_smile:

Sorted thank you :slight_smile:

I am glad to hear it

If you had originally posted the full error message then the cause of the problem would have been more obvious because the location of where setup() was originally defined would have been obvious

As it was, @david_2018, @sterretje and I had to rely on our spidey senses to guess the cause of the problem. It is almost as though we had seen it before ...

3 Likes

You need to fix your colour (color) tags :smiley: I did notice it before.

Whoops, yes I do

I am sure that it used to work though

I know. I think it's the spaces.

For now I have simply removed the color attribute

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

EDIT

It was the spaces

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Sorry :slight_smile: And thanks again, much appreciated. 1 now knows in future :slight_smile: