Writing my own libraries ERROR

So I’ve written in a variety of languages, so I understand the concepts, but I’m fairly new to C++. I’m trying to write my own libraries for a project I’m working on developing some some things for the Arduino. But I keep getting an error that my variable is not declared in the current scope. I’ve read the “how to” on libraries here (Arduino - LibraryTutorial), and thought that if I declared my variables in the class, and then populated them when the library is initialized, then those variables would be populated throughout the rest of the functions in my library.

All I’m trying to do here is initialize the pins for a 7 segment display, and then use those same pins when other functions are called upon. Here take a look:


#ifndef SevenSeg_h
#define SevenSeg_h

#include "Arduino.h"

class SevenSeg
		SevenSeg(int sevsegA, int sevsegB, int sevsegC, int sevsegD, int sevsegE, int sevsegF, int sevsegG, int sevsegP);
		void displayChar(String Char);
		void turnOff();
		int _sevsegA;
		int _sevsegB;
		int _sevsegC;
		int _sevsegD;
		int _sevsegE;
		int _sevsegF;
		int _sevsegG;
		int _sevsegP; 



SevenSeg::SevenSeg(int sevsegA, int sevsegB, int sevsegC, int sevsegD, int sevsegE, int sevsegF, int sevsegG, int sevsegP)
	pinMode(sevsegA, OUTPUT);
	pinMode(sevsegB, OUTPUT);
	pinMode(sevsegC, OUTPUT);
	pinMode(sevsegD, OUTPUT);
	pinMode(sevsegE, OUTPUT);
	pinMode(sevsegF, OUTPUT);
	pinMode(sevsegG, OUTPUT);
	pinMode(sevsegP, OUTPUT);
	_sevsegA = sevsegA;
	_sevsegB = sevsegB;
	_sevsegC = sevsegC;
	_sevsegD = sevsegD;
	_sevsegE = sevsegE;
	_sevsegF = sevsegF;
	_sevsegG = sevsegG;
	_sevsegP = sevsegP;

void SevenSeg::displayChar(String Char)


	//Conditions for displaying segment a
	if(Char!="1" && Char != "4")

	//Conditions for displaying segment b
	if(Char != "5" && Char != "6" && Char !="C" && Char !="E" && Char !="F")

	//Conditions for displaying segment c
	if(Char !="2" && Char !="C" && Char !="E" && Char !="F")

	//Conditions for displaying segment d
	if(Char != "1" && Char !="4" && Char !="7" && Char !="A" && Char !="F")

	//Conditions for displaying segment e 
	if(Char == "2" || Char =="6" || Char == "8" || Char=="0")
	//Conditions for displaying segment f
	if(Char != "1" && Char !="2" && Char!="3" && Char !="7")


	//Conditions for displaying segment g
	if (Char!="0" && Char!="1" && Char !="7" && Char !="C" && Char !="D")

	//The only way to tell some of the letters apart from numbers is that when it's a Letter, the DP will be on (example, both B and 8, illuminate the same segments, so B will have the DP on.)
	if (Char=="A" || Char=="B" || Char=="C" || Char=="D" || Char=="E" || Char=="F")


void SevenSeg::turnOff()



My Project File

#include "Arduino.h"
#include "SevenSeg.h"

SevenSeg sevenSeg(22,23,24,25,26,27,28,29);

void setup() {

void loop() {
  for(int i=0;i<10;i++)

I’m just using the “A” as a test. And here’s the error I get:

SevenSeg.cpp:121:15: error: '_sevsegP' was not declared in this scope



exit status 1
Error compiling.

So it appears that when the “turnOff” function is called, that it doesn’t recongnize that my private variable “_sevsegP” is not available to the function.

Can anyone tell me what I’m missing? Thanks.

Sevenseg.cpp also needs to #include the header file.

void SevenSeg::displayChar(String Char)

Why are you wasting resources to use a String to hold a single character. Just let the function take a char.

The hardware may not be ready when your constructor is invoked. You should NOT be diddling with pins in the constructor.

You should have a begin() method where you diddle with the hardware.

If the compiler agrees that _sevsegA, _sevsegB, etc. are accessible, then there is something different between your header file and your source file.

Create a zip file and attach it here, of the code that you are actually compiling.