Hilfe bei Anwendung Sharp IR GP2Y0A21YK0F

Hallo,
Ich möchte den Sensor GP2Y0A21YK0F von Sharp anwenden und habe dazu zunächst einen kleinen Sketch ausprobiert.

/******************************************************************
 Created with PROGRAMINO IDE for Arduino - 09.03.2021 10:55:26
 Project     : Test Sharp IR Sensor
 Libraries   :
 Author      : Benne de Bakker
 Description :
******************************************************************/
/*SHARP GP2Y0A21YK0F IR distance sensor with Arduino and SharpIR library example code. More info: https://www.makerguides.com */
// Include the library:
#include <SharpIR.h>
// Define input pin:
#define IRPin A0

// Create variable to store the distance:
int distance_cm;
// Create a new instance of the SharpIR class:
SharpIR mySensor(SharpIR::GP2Y0A21YK0F,IRPin );
//SharpIR mySensor(model,IRPin);
void setup() {
  // Begin serial communication at a baudrate of 9600:
  Serial.begin(9600);
}
void loop() {
  // Get a distance measurement and store it as distance_cm:
  distance_cm = mySensor.getDistance(false);
  // Print the measured distance to the serial monitor:
  Serial.print("Mean distance: ");
  Serial.print(distance_cm);
  Serial.println(" cm");
  delay(1000);
}

Ich bekomme jedoch folgende Fehlermeldung, zu der ich keine Lösung finde:

libraries\SharpIR\SharpIR.cpp.o (symbol from plugin): In function SharpIR::getDistance(bool)': (.text+0x0): multiple definition of SharpIR::getDistance(bool)'
sketch\SharpIR.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
exit status 1
Fehler beim Kompilieren für das Board Arduino Uno.

Die einfache Schaltung ist als Anlage beigefügt.

`SharpIR::getDistance(bool)' wird in mehreren Orten (Sketch Bibliothek oder Arduino-Gedös) mehrfach definiert. Nur eine Definition ist zulässig.

Dieser Sensor ist so einfach zu benutzen. Wieso brauchst Du denn eine Bibliothek?

zB: https://www.instructables.com/How-to-Use-the-Sharp-IR-Sensor-GP2Y0A41SK0F-Arduin/

Grüße Uwe

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.