Your whole library is a complete mess, I am not supprised the compiler can't make heads or tails of it.
(1) <string.h> is a system library, and calling so anything "STRING.h" is just likely to cause confusion.
(2) You don't declare class variables in the constructor, you do it in the class definition:
class STRING {
String stringA;
...
(3) the instance 'keypad' does not exist in your library, it was declared in your main sketch. Trying to using keypad.getKey() in your library is just plain wrong. You could perhaps pass a pointer to the keypad instance to each of the functions which use it.
(4) you have used the variable 'key' in both addString() and total(), and yet it is declared in neither of them, nor is it declared as a class variable - in otherwords, it doesn't exist.
Fixing all of those, the problem goes away.
The error message you are getting is simply either Arduino, the preprocessor, or the compiler getting confused between your STRING.h and the C standard libraries string.h. Renaming the library gets rid of that message.
I haven't bothered to try and work out what the library is supposed to do and whether or not it does that, but this at least compiles:
.h
#ifndef ImNotCalledString_H
#define ImNotCalledString_H
#include <Arduino.h>
#include <Keypad.h>
class ImNotCalledString {
String stringA;
String stringB;
String stringC;
String stringD;
char key;
char x;
float a;
float b;
float c;
float d;
public:
void switcher(Keypad* keypad);
void addToString(Keypad* keypad);
void total(Keypad* keypad);
};
#endif
.cpp
#include "ImNotCalledString.h"
void ImNotCalledString::switcher(Keypad* keypad) {
key = keypad->getKey();
switch(key) {
case 'a':
x = 'a';
Serial.println();
Serial.print("string A = ");
Serial.print(stringA);
break;
case 'b':
x = 'b';
Serial.println();
Serial.print("string B = ");
Serial.print(stringB);
break;
case 'c':
x = 'c';
Serial.println();
Serial.print("string C = ");
Serial.print(stringC);
break;
case 'd':
x = 'd';
Serial.println();
Serial.print("string D = ");
Serial.print(stringD);
}
}
void ImNotCalledString::addToString(Keypad* keypad) {
if(x == 'a') {
switch(key) {
case '1':
stringA += "1";
Serial.print("1");
break;
case '2':
stringA += "2";
Serial.print("2");
break;
case '3':
stringA += "3";
Serial.print("3");
break;
case '4':
stringA += "4";
Serial.print("4");
break;
case '5':
stringA += "5";
Serial.print("5");
break;
case '6':
stringA += "6";
Serial.print("6");
break;
case '7':
stringA += "7";
Serial.print("7");
break;
case '8':
stringA += "8";
Serial.print("8");
break;
case '9':
stringA += "9";
Serial.print("9");
break;
case '0':
stringA += "0";
Serial.print("0");
break;
case '*':
stringA = "";
Serial.println();
Serial.println("string A cleared");
Serial.print("string A = 0");
}
}
if(x == 'b') {
switch(key) {
case '1':
stringB += "1";
Serial.print("1");
break;
case '2':
stringB += "2";
Serial.print("2");
break;
case '3':
stringB += "3";
Serial.print("3");
break;
case '4':
stringB += "4";
Serial.print("4");
break;
case '5':
stringB += "5";
Serial.print("5");
break;
case '6':
stringB += "6";
Serial.print("6");
break;
case '7':
stringB += "7";
Serial.print("7");
break;
case '8':
stringB += "8";
Serial.print("8");
break;
case '9':
stringB += "9";
Serial.print("9");
break;
case '0':
stringB += "0";
Serial.print("0");
break;
case '*':
stringB = "";
Serial.println();
Serial.println("string B cleared");
Serial.print("string B = 0");
}
}
if(x == 'c') {
switch(key) {
case '1':
stringC += "1";
Serial.print("1");
break;
case '2':
stringC += "2";
Serial.print("2");
break;
case '3':
stringC += "3";
Serial.print("3");
break;
case '4':
stringC += "4";
Serial.print("4");
break;
case '5':
stringC += "5";
Serial.print("5");
break;
case '6':
stringC += "6";
Serial.print("6");
break;
case '7':
stringC += "7";
Serial.print("7");
break;
case '8':
stringC += "8";
Serial.print("8");
break;
case '9':
stringC += "9";
Serial.print("9");
break;
case '0':
stringC += "0";
Serial.print("0");
break;
case '*':
stringC = "";
Serial.println();
Serial.println("string C cleared");
Serial.print("string C = 0");
}
}
if(x == 'd') {
switch(key) {
case '1':
stringD += "1";
Serial.print("1");
break;
case '2':
stringD += "2";
Serial.print("2");
break;
case '3':
stringD += "3";
Serial.print("3");
break;
case '4':
stringD += "4";
Serial.print("4");
break;
case '5':
stringD += "5";
Serial.print("5");
break;
case '6':
stringD += "6";
Serial.print("6");
break;
case '7':
stringD += "7";
Serial.print("7");
break;
case '8':
stringD += "8";
Serial.print("8");
break;
case '9':
stringD += "9";
Serial.print("9");
break;
case '0':
stringD += "0";
Serial.print("0");
break;
case '*':
stringD = "";
Serial.println();
Serial.println("string D cleared");
Serial.print("string D = 0");
}
}
}
void ImNotCalledString::total(Keypad* keypad) {
key = keypad->getKey();
if(key == '#') {
Serial.println();
Serial.print("total = ");
a = stringA.toInt();
b = stringB.toInt();
c = stringC.toInt();
d = stringD.toInt();
Serial.println(a + b + c + d);
}
}
.ino
#include <ImNotCalledString.h>
#include <Keypad.h>
const byte rows = 4; //initializes the keypad
const byte cols = 4;
char keys [rows][cols] = {
{'1','2','3','a'},
{'4','5','6','b'},
{'7','8','9','c'},
{'*','0','#','d'}
};
byte rowPins[rows] = {22, 24, 26, 28};
byte colPins[cols] = {30, 32, 34, 36};
Keypad _keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols ); //makes the keymap for the keypad
ImNotCalledString string;
void setup() {
Serial.begin(9600);
}
void loop() {
string.switcher(&_keypad); //switches what string is being edited
string.addToString(&_keypad); //adds keys pressed to whatever string is currently being edited and prints current string
string.total(&_keypad); //converts strings to ints and adds/prints them to the serial monitor
}