I'm trying to learn about making my own library and I'm stumped on using a class from another library in my library. I've been looking at libraries I have on my computer and searching Google, but I can't figure it out.
Here is a simple sketch that displays some text on a LCD screen. This works fine.
I'd like to move the display. lines into separate .h and .cpp files. These will be in the same directory as ino, not in the libraries folded. This is what I have for
MyTest.ino. I know I didn't create oledMenu object - I don't know how.
I don't know if I'm on the right track on not. I'm not sure how to create and use the Adafruit_SSD1306 in my cpp file. And I don't know how to create the Menu object (oledMenu.) to use in my ino. I tried a few different ways, but got compile errors.
Here's what I came up with, it compiles but doesn't work. When I upload to my Leonardo it locks up and I actually lose my serial connection on the USB (I'm using a mac). The Seraial Port from the IDE menu drop down disappears. I'd actually prefer to not pass the display object in oledMenu.displayChoice(display, 1); I'd like to just have oledMenu.displayChoice(1);, but I couldn't figure that out.
Notice how in those examples the variable name is not identical (Variable type has an upper case first letter, variable name has a lower case first letter). Personally I think that is a load of complete cobblers. What happens if you need to pass two variables of the same type, do you give them both the same name? no, of course not, you give the variable a sensible name which says what it does (e.g. strcpy(char* source, char* desitination))
I think I know why my Leonardo freezes, I should not be putting all this code in the constructor (Menu::Menu). It should to in a separate function that's called form setup().
ScottG:
I think I know why my Leonardo freezes, I should not be putting all this code in the constructor (Menu::Menu). It should to in a separate function that's called form setup().
Absolutely it should not be in the constructor. That's why a lot of libraries use the "begin" function.