HELP ME WITH IR!

SORRY FOR MY ENGLISH :sweat_smile: :sweat_smile: :sweat_smile:

hi i’m writing this code for a school project ,i shulde turn on led with a remote and this is done, it run perfectly but when i write a loop for alternate on of the led ide give me this error:

Arduino:1.6.12 (Windows 7), Scheda:"Arduino/Genuino Uno"

C:\Users\antonio\Documents\Arduino\sketch_oct21ab\sketch_oct21ab.ino: In function 'void loop()':

sketch_oct21ab:96: error: a function-definition is not allowed here before '{' token

 void setup() {

              ^

sketch_oct21ab:104: error: a function-definition is not allowed here before '{' token

void loop() {

        ^

C:\Users\antonio\Documents\Arduino\sketch_oct21ab\sketch_oct21ab.ino: At global scope:

sketch_oct21ab:129: error: expected declaration before '}' token

}

^

exit status 1
a function-definition is not allowed here before '{' token

this is the code:

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
String stato;

void setup()
{
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value);

    if (results.value == 16) {
      stato = "acceso1";
      digitalWrite(3, HIGH);
    }
    else if (results.value == 2064) {
      stato = "acceso2";
      digitalWrite(5, HIGH);
    }
    else if (results.value == 1040) {
      stato = "acceso3";
      digitalWrite(6, HIGH);
    }




    if (results.value == 3088) {
      stato = "spento1";
      digitalWrite(3, LOW);
    }
    else if (results.value == 528) {
      stato = "spento2";
      digitalWrite(5, LOW);
    }
    else if (results.value == 2576) {
      stato = "spento3";
      digitalWrite(6, LOW);
    }



    else if (results.value == 1552) {
      stato = "mantieniacceso";
    }
    else if (results.value == 2320) {
      stato = "spento";
    }
    else if (results.value == 1168) {
      stato = "intensità+";
    }

    if (stato == "acceso1") {
      digitalWrite(3, HIGH);
    }
    else if (stato == "acceso2") {
      digitalWrite(5, HIGH);
    }
    else if (stato == "acceso3") {
      digitalWrite(6, HIGH);
    }


    if (stato == "spento1") {
      digitalWrite(3, LOW);
    }
    else if (stato == "spento2") {
      digitalWrite(5, LOW);
    }
    else if (stato == "spento3") {
      digitalWrite(6, LOW);
    }



    else if (stato == "mantieniacceso") {
      digitalWrite(3, HIGH);
      digitalWrite(5, HIGH);
      digitalWrite(6, HIGH);
    }
    else if (stato == "spento") {
      digitalWrite(3, LOW);
      digitalWrite(5, LOW);
      digitalWrite(6, LOW);
    }
    else if (stato == "intensità+") {
      void setup() {
        // initialize digital pin LED_BUILTIN as an output.
        pinMode(3, OUTPUT);
        pinMode(5, OUTPUT);
        pinMode(6, OUTPUT);
      }

      // the loop function runs over and over again forever
      void loop() {
        digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(1000);                       // wait for a second
        digitalWrite(3, LOW);    // turn the LED off by making the voltage LOW
        delay(1000);


        // wait for a second
        digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(500);                       // wait for a second
        digitalWrite(5, LOW);    // turn the LED off by making the voltage LOW
        delay(500);


        digitalWrite(6, HIGH);   // turn the LED on (HIGH is the voltage level)
        delay(250);                       // wait for a second
        digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
        delay(250);
      }
    }
  }


  irrecv.resume(); // Receive the next value
}
}

sketch_oct21ab.ino (2.74 KB)

Use the function in the Arduino Development Window under tools to format your code. You will then see, by the strange indentation, where there is a missing '}' or '{' or ';'

How many setup() functions should there be in an Arduino program and where should it or they be placed ?

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :)

thank's TomGeorge i have fixed my post ,now is more readable

antroma47:
thank’s TomGeorge i have fixed my post ,now is more readable

But you have not answered my question about the setup() function. How many times does void setup() appear in your code ?

. . . or the multiple loop() function, which is not permitted.
You have 2 closing brackets ‚Äė}‚Äô at the same level at the end of your code (after formatting it) which also indicates a problem, but that might simply be a consequence of the first error.

or the multiple loop() function,

I was saving that problem for later !