So, I tried making my first Library and this is the error that showed up with verbose on:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Uno"
C:\Users\Dell\AppData\Local\Temp\arduino_modified_sketch_144881\sketch_sep14a.ino: In function 'void loop()':
sketch_sep14a:13:20: error: 'add' was not declared in this scope
Serial.println ( add ( 5, 2 ) );
^~~
C:\Users\Dell\AppData\Local\Temp\arduino_modified_sketch_144881\sketch_sep14a.ino:13:20: note: suggested alternative: 'rand'
Serial.println ( add ( 5, 2 ) );
^~~
rand
exit status 1
'add' was not declared in this scope
Even though add was clearly declared in the .cpp code below. My library just gives the functions to add, subtract, multiply and divide. Library Name - Operator.
I compressed my Operator.h and Operator .cpp in a ZIP folder and added it to the Arduino libraries list. No errors during the #include<Operator.h> statement.
Operator.h
#ifndef Operator_h
#define Operator_h
#include <Arduino.h>
class Operator
{
public:
int add ( int a, int b );
int subtract( int a, int b );
int multiply( int a, int b );
int divide( int a, int b );
};
#endif
Operator.cpp
#include <Arduino.h>
#include <Operator.h>
int _total;
int add ( int a, int b )
{
_total = a + b;
return _total;
}
int subtract ( int a, int b )
{
_total = a - b;
return _total;
}
int multiply ( int a, int b )
{
_total = a * b;
return _total;
}
int divide ( int a, int b )
{
_total = a / b;
return _total;
}
Code I tried doing: // The code in the Arduino IDE in which the error showed up.
#include <Operator.h>
void setup() {
// put your setup code here, to run once:
Serial.begin ( 9600 );
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println ( add ( 5, 2 ) );
}
You can see I have declared add() there. Why is the error showing up? What have I done wrong? The zipped folder of this library is attached below. Please help me out. Thanks!
Operator_Library.zip (706 Bytes)