Skip to main content
Arduino

Return to Question

Commonmark migration
Source Link

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.

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.

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.

Source Link
ATE-ENGE
  • 941
  • 3
  • 19
  • 32

Arduino Interrupts Classes and Namespace

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.

AltStyle によって変換されたページ (->オリジナル) /