Hi everyone,
i have a problem with a 2D pointer array. I’m trying to code a menu for a I2C Display. The idea is that each column of my 2D Pointer Array (“matrix”) represents a individual menu with entries on its own. Each entry should consist of a structure that contains the displayed text and a number, that corresponds to the next menu he is supposed to jump to.
So i tried this, but i get nonsensical output on the display:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
class Disp_menu
{
public:
Disp_menu();
void addElement(int layer,char title,int link);
void delElement();
void draw();
private:
typedef struct{
char title[20];
int link;
} element;
element **_menu;
};
Disp_menu::Disp_menu(){
_menu = (element**) calloc(1,sizeof(element*));
element el1 = {"Hallo",0};
_menu[0][0] = el1;
}
void Disp_menu::draw(){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(_menu[0][0].title);
Serial.println(_menu[0][0].title);
display.display();
delay(2000);
}
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.display();
delay(2000);
menu.draw();
}
void loop() {
// put your main code here, to run repeatedly:
}
What am i missing? I would be thankful to any kind of help