Arduino - Como implementar una función previamente definida

 
Vista:
sin imagen de perfil

Como implementar una función previamente definida

Publicado por Alberto (1 intervención) el 10/05/2017 18:12:43
El problema es que trato de utilizar la función "displayLed", que lo que debe hacer es sacar un numero por un display, pero me da error, y no se llega a implementar. He probado añadiéndole el fichero "displayLed" (la función), pero sigue sin funcionar.

¿Como puedo hacer para que de una p*** vez me compile?

Ahhhh y muchas gracias de antemano ;)

El código del sketch es: (displayLed a partir de la línea 24)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "IRLremote.h"
const int interruptIR = 0;
 
uint8_t IRProtocol = 0;  // Variables para recibir los datos
uint16_t IRAddress = 0;
uint32_t IRCommand = 0;
 
void setup()
   {    Serial.begin(115200);          // Fijate en la velocidad
        for (int i = 3 ; i<10 ; i++)
        pinMode(i, OUTPUT);
 
        IRLbegin<IR_ALL>(interruptIR);
   }
   void loop()
   {    uint8_t oldSREG = SREG;  // Parar las interrupciones
        cli();
        if (IRProtocol)
          { for (int k =3 ; k <10 ; k++){                       // Apaga todos los leds antes de un nuevo ciclo
                              digitalWrite(k, LOW);
              switch (IRCommand) // Aqui tenemos la clausula switch con sus case:
                  { case 0x6897:
                        Serial.println("0");
                        displayLed(0);
                        break;
                    case 0x30CF:
                        Serial.println("1");
                        displayLed(1);
                         break;
                    case 0x18E7:
                         Serial.println("2");
                         displayLed(2);
                         break;
                    case 0x7A85:
                         Serial.println("3");
                         displayLed(3);
                         break;
                    case 0x10EF:
                        Serial.println("4");
                        displayLed(4);
                        break;
                   case 0x38C7:
                        Serial.println("5");
                        displayLed(5);
                        break;
                   case 0x5AA5:
                        Serial.println("6");
                        displayLed(6);
                        break;
                   case 0x42BD:
                        Serial.println("7");
                        displayLed(7);
                        break;
                   case 0x4AB5:
                        Serial.println("8");
                        displayLed(8);
                        break;
                   case 0x52AD:
                        Serial.println("9");
                        displayLed(9);
                        break;
                   case 0xFFFF:
                        Serial.println("ERROR");
                        digitalWrite(3, HIGH);
                        digitalWrite(4, HIGH);
                        digitalWrite(5, HIGH);
                        digitalWrite(7, HIGH);
                        digitalWrite(8, HIGH);
                        break;
                   case 0x22DD:
                        Serial.println("Cuenta atras");
 
                           }
 
 
              }
              IRProtocol = 0;
          }
       SREG = oldSREG;
    }
void IREvent(uint8_t protocol, uint16_t address, uint32_t command)
   {
        IRProtocol = protocol;  // Recogemos los valores
        IRAddress = address;
        IRCommand = command;
   }


El fichero que le he añadido:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
int Numero;
  pinMode(3,HIGH);
  pinMode(4,HIGH);
  pinMode(5,HIGH);
  pinMode(6,HIGH);
  pinMode(7,HIGH);
  pinMode(8,HIGH);
  pinMode(9,HIGH);
 
}
 
void displayLed( Numero){
 
 
  switch (Numero){
 
    case 0:
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 1:
    digitalWrite(6,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 2:
    digitalWrite(3,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    break;
 
    case 3:
    digitalWrite(3,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 4:
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 5:
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9;HIGH);
    break;
 
    case 6:
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 7:
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 8:
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    break;
 
    case 9:
    digitalWrite(3,HIGH);
    digitalWrite(4,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(8,HIGH);
    digitalWrite(9,HIGH);
    break;
  }
}

Por último el error que me da es:

Arduino:1.8.2 (Windows 8), Tarjeta:"Arduino/Genuino Uno"

In file included from C:\*\*\*\Arduino\Mis funciones\IR\PruebaMandoIR\PruebaMandoIR\PruebaMandoIR.ino:1:0:

C:\*\*\*\Arduino\libraries\IRLremote/IRLremote.h:72:1: warning: 'typedef' was ignored in this declaration

};

^

C:\*\*\*\Arduino\Mis funciones\IR\PruebaMandoIR\PruebaMandoIR\PruebaMandoIR.ino: In function 'void loop()':

PruebaMandoIR:24: error: 'displayLed' was not declared in this scope

displayLed(0);

^

C:\*\*\*\Arduino\Mis funciones\IR\PruebaMandoIR\PruebaMandoIR\displayLed.ino: At global scope:

displayLed:2: error: expected constructor, destructor, or type conversion before '(' token

pinMode(3,HIGH);

^

displayLed:3: error: expected constructor, destructor, or type conversion before '(' token

pinMode(4,HIGH);

^

displayLed:4: error: expected constructor, destructor, or type conversion before '(' token

pinMode(5,HIGH);

^

displayLed:5: error: expected constructor, destructor, or type conversion before '(' token

pinMode(6,HIGH);

^

displayLed:6: error: expected constructor, destructor, or type conversion before '(' token

pinMode(7,HIGH);

^

displayLed:7: error: expected constructor, destructor, or type conversion before '(' token

pinMode(8,HIGH);

^

displayLed:8: error: expected constructor, destructor, or type conversion before '(' token

pinMode(9,HIGH);

^

displayLed:10: error: expected declaration before '}' token

}

^

exit status 1
'displayLed' was not declared in this scope

Este reporte podría tener más información con
"Mostrar salida detallada durante la compilación"
opción habilitada en Archivo -> Preferencias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder