ADCtouch library issue

I wrote a vary basic sketch to run some test with this library; this is the code (adapted from a source on WEB):

#include <ADCTouch.h>

ADCTouchClass ADCTouch;
int ref0;  //reference values to remove offset

void setup() {
  Serial.begin(9600);
  delay(1000);
  ref0 = ADCTouch.read(A0, 500);  //create reference values to
}

void loop() {
  int value0 = ADCTouch.read(A0);  //no second parameter
  value0 -= ref0;  //remove offset

  Serial.print(value0 > 40);  //send (boolean) pressed or not pressed
  Serial.print("\t");         //use if(value > threshold) to get the state of a button
  Serial.print(value0);  //send actual readingc
  Serial.print("\t");
  delay(100);
}

I included the ADC Touch library 1.0.3 (by Martin 2250) from the Library Manager.
Trying to upload the code I got an error never seen before that I do not understand:

C:\Users\Utente\AppData\Local\Temp\arduino\sketches\D875B039B952878A0C207D7AD80CD4C3\libraries\ADCTouch\ADCTouch.cpp.o (symbol from plugin): In function `ADCTouchClass::read(unsigned char, int)':
(.text+0x0): multiple definition of `ADCTouch'
C:\Users\Utente\AppData\Local\Temp\arduino\sketches\D875B039B952878A0C207D7AD80CD4C3\sketch\TestADCtouch.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1

This is unexpected and surprising since the code is minimal and the library, as I see on GitHub, has more then 5 years, so it should have been used a lot.
Thanks

Remove that line from your sketch. This object is already defined in the library code.

No, the ADCTouchClass object is required by the sketch. I solved changing its name to someyhing different, like ADCT.

If you use the library available in the library manager this is wrong. The last line of the .h file:

extern ADCTouchClass ADCTouch;

The corresponding instantiation is in the .cpp file.

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