I'm working inside the Arduino IDE environment and have made a class that builds on the Adafruit RDG LCD with interrupts While looking at how to combine the Attach Interrupt()
into my class I came across this post about using namespaces
Why make a class then? What about a namespace?
A class with one instance is like a group with one person in it.
-nickgammon
Understanding that Mr.Gammon is kind of a big deal around these parts, I'd like to understand how to insert/alter my current class into a namespace format. Currently, the most in-depth tutorial I've found is here, but I don't see how I would mix in the Attach Interrupt()
function
Right now, my code looks like
/**** Pre-Setup *****/
#define Menu_PIN 3
voltile bool flag;
//Init Class
class LcdMenu : public Adafruit_RGBLCDShield
{
public:
MenuFoo()
}
LcdMenu LcdM;
//run Setup
void setup() /****** SETUP: RUNS ONCE ******/
{
pinMode(Menu_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(Menu_PIN), ProcMenu, FALLING);
}
void loop()
{
if(flag){
LcdM.MenuFoo();
flag=false;
}
}
//Handles Inturrupts for Class
void ProcMenu()
{
flag=true;
}
//define MenuFoo
void LcdMenu::MenuFoo(){[code]}
As I understand it, Implementing a namespace would eliminate the need for the ProcMenu()
function making my code easier to read/maintain.
ProcMenu()
into theLcdMenu
class. It will have to be static and then you can write member function to hide theattachInterrupt()
e.g.LcdM.begin(MENU_PIN);
LCD Menu
is aAdafruit_RGBLCDShield
As to why overall, I wanted a way to group the LCD functions together.