How to access gadgeteer objects outside program.cs?

Hi. Let’s assume that my project contains mainboard and button.
At the Program.generated.cs there is an instance of private button which may be access on the program.cs class by just calling button.something. But what if I would like to have another class called myProgram and there I would like to call button.doSomething, How is it possible?

@ andre.m - I tried the first method. I changed the private to public but when trying to create instance of this button from another class with: Program.Button - It doesn’t exist. Why? Should I add “Static” as well?

if you want a class to have a reference to an object, then you need to pass it a reference to that object. There is no global namespace.

I often create a singleton class, which contains a common pool of “global” references. This consolidates common references into a single class.

1 Like