Thanks so much your reply!
With the F constructor everthing is drawn fine but still not really the speed I want. Is it possible to achieve 25fps on an Arduino with u8g2lib?
This is my current full code:
.h-File:
#ifndef SCRoboDraw_h
#define SCRoboDraw_h
#include "Arduino.h"
#include <U8g2lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif
extern U8G2_SSD1306_128X64_NONAME_F_HW_I2C *u8g2;
class SCRoboDraw
{
public:
SCRoboDraw();
void initScreen();
void draw();
void drawLine();
private:
unsigned long lastFrame = 0;
int frameRate = 40; // 1000ms/25fps;
int yPos = 0;
};
#endif
.cpp-File
#include "Arduino.h"
#include "SCRoboDraw.h"
U8G2_SSD1306_128X64_NONAME_F_HW_I2C *u8g2;
SCRoboDraw::SCRoboDraw()
{
}
void SCRoboDraw::initScreen()
{
u8g2 = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0,U8X8_PIN_NONE);
u8g2->begin();
}
void SCRoboDraw::draw()
{
if(millis()-lastFrame >= frameRate)
{
lastFrame = millis();
u8g2->clearBuffer();
drawLine();
u8g2->sendBuffer();
}
}
void SCRoboDraw::drawLine()
{
yPos += 1;
u8g2->drawLine(0,yPos,127,56);
if(yPos > 64)
{
yPos = 0;
}
}