Forum: Mikrocontroller und Digitale Elektronik custom Library – multiple definitions


von Elias *. (green_phanta)


Lesenswert?

Aloha!

Ich versuche gerade die Keypad Library so zu modifizieren, dass ich sie 
mit PCF 8574 Port Expandern betreiben kann. Der Einfachheit wegen habe 
ich in der Keypad Library wiederum eine Library für den PCF.

Aber ich bekomme es nicht zum laufen ohne folgende Fehlermeldung:
1
/var/folders/v0/xh4cnpz96rq5fw8nk7m1g0jw0000gp/T/arduino_build_43838/libraries/Keypad/Keypad.cpp.o: In function `Keypad::numKeys()':
2
/Users/elias/Documents/Arduino/libraries/Keypad/src/Keypad.h:81: multiple definition of `PCF'
3
/var/folders/v0/xh4cnpz96rq5fw8nk7m1g0jw0000gp/T/arduino_build_43838/sketch/test.ino.cpp.o:/Users/elias/Documents/Arduino/test/test.ino:33: first defined here
4
/Applications/Arduino.app/Contents/Java/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld: Disabling relaxation: it will not work with multiple definitions
5
collect2: error: ld returned 1 exit status
6
Fehler beim Kompilieren für das Board Teensy 3.6.

An Keypad.cpp habe ich nichts verändert, an Keypad.h habe ich 
digitalRead/digitalWrite in PCF.read/PCF.write geändert und
1
#include "PCF8574.h"
2
PCF8574 PCF(0x20);
habe ich oben eingefügt.
Was mache ich falsch?

Danke!



Hier der ganze Code der Keypad.h:
1
#ifndef KEYPAD_H
2
#define KEYPAD_H
3
4
#include "Key.h"
5
#include "PCF8574.h"
6
PCF8574 PCF(0x20);
7
8
// bperrybap - Thanks for a well reasoned argument and the following macro(s).
9
// See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480
10
#ifndef INPUT_PULLUP
11
#warning "Using  pinMode() INPUT_PULLUP AVR emulation"
12
#define INPUT_PULLUP 0x2
13
#define pinMode(_pin, _mode) _mypinMode(_pin, _mode)
14
#define _mypinMode(_pin, _mode)  \
15
do {               \
16
  if(_mode == INPUT_PULLUP)   \
17
    pinMode(_pin, INPUT);   \
18
    PCF.write(_pin, 1);   \
19
  if(_mode != INPUT_PULLUP)   \
20
    pinMode(_pin, _mode);   \
21
}while(0)
22
#endif
23
24
25
#define OPEN LOW
26
#define CLOSED HIGH
27
28
typedef char KeypadEvent;
29
typedef unsigned int uint;
30
typedef unsigned long ulong;
31
32
// Made changes according to this post http://arduino.cc/forum/index.php?topic=58337.0
33
// by Nick Gammon. Thanks for the input Nick. It actually saved 78 bytes for me. :)
34
typedef struct {
35
    byte rows;
36
    byte columns;
37
} KeypadSize;
38
39
#define LIST_MAX 10    // Max number of keys on the active list.
40
#define MAPSIZE 10    // MAPSIZE is the number of rows (times 16 columns)
41
#define makeKeymap(x) ((char*)x)
42
43
44
//class Keypad : public Key, public HAL_obj {
45
class Keypad : public Key {
46
public:
47
48
  Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols);
49
50
  virtual void pin_mode(byte pinNum, byte mode) { pinMode(pinNum, mode); }
51
  virtual void pin_write(byte pinNum, boolean level) { PCF.write(pinNum, level); }
52
  virtual int  pin_read(byte pinNum) { return PCF.read(pinNum); }
53
54
  uint bitMap[MAPSIZE];  // 10 row x 16 column array of bits. Except Due which has 32 columns.
55
  Key key[LIST_MAX];
56
  unsigned long holdTimer;
57
58
  char getKey();
59
  bool getKeys();
60
  KeyState getState();
61
  void begin(char *userKeymap);
62
  bool isPressed(char keyChar);
63
  void setDebounceTime(uint);
64
  void setHoldTime(uint);
65
  void addEventListener(void (*listener)(char));
66
  int findInList(char keyChar);
67
  int findInList(int keyCode);
68
  char waitForKey();
69
  bool keyStateChanged();
70
  byte numKeys();
71
72
private:
73
  unsigned long startTime;
74
  char *keymap;
75
    byte *rowPins;
76
    byte *columnPins;
77
  KeypadSize sizeKpd;
78
  uint debounceTime;
79
  uint holdTime;
80
  bool single_key;
81
82
  void scanKeys();
83
  bool updateList();
84
  void nextKeyState(byte n, boolean button);
85
  void transitionTo(byte n, KeyState nextState);
86
  void (*keypadEventListener)(char);
87
};
88
89
#endif

von Peter II (Gast)


Lesenswert?

> Elias *. schrieb:
> Keypad.h:
> PCF8574 PCF(0x20);


in einer Headdatei legt man keine Objekte oder Variablen an!

von Elias *. (green_phanta)


Lesenswert?

ok. Wie kann ich dann auf das Objekt PCF in dieser Zeile zugreifen?
1
virtual void pin_write(byte pinNum, boolean level) { digitalWrite(pinNum, level); }


Wenn ich PCF nicht deklariere bekomme ich ja: 'PCF' was not declared …
Was bedeutet denn dieses "virtual void" überhaupt?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.