working version 1

This commit is contained in:
cally22
2023-07-08 22:44:00 +02:00
parent d1816ba485
commit 6cc938d45b
3 changed files with 105 additions and 59 deletions
+19 -30
View File
@@ -1,3 +1,5 @@
#include "HardwareSerial.h"
#include "Print.h"
#ifndef OledDisplay_h
#define OledDisplay_h
@@ -12,22 +14,18 @@
class OledDisplay {
private:
Adafruit_SSD1306 display{SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET};
int currentLine = 0;
public:
void setup();
void write(String msg);
void clear();
void droneMessage(String msg);
void writeLine(char* msg, int line);
};
void OledDisplay::setup() {
// display module
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // I2C address = 0x3C
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.clearDisplay();
display.setTextColor(WHITE, BLACK);
clear();
display.print("Loading");
display.display();
for (int i = 0; i < 3; i++) {
@@ -35,38 +33,29 @@ void OledDisplay::setup() {
display.display();
delay(500);
}
display.clearDisplay();
clear();
delay(10);
write("Display is ready");
}
void OledDisplay::write(String msg) {
if (currentLine >= 60) {
currentLine = 0;
}
display.setCursor(0, currentLine);
display.print(msg);
display.print("Display is ready");
display.display();
currentLine+=10;
}
void OledDisplay::clear() {
display.clearDisplay();
display.setCursor(0, 0);
currentLine = 0;
}
void OledDisplay::droneMessage(String msg) {
clear();
const char delimiter[] = "|";
char* token = strtok(msg.c_str(), delimiter);
while (token != NULL) {
Serial.println(token);
write(String(token));
token=strtok(NULL, delimiter);
void OledDisplay::writeLine(char* msg, int line) {
int x = 0;
int y = line * 10;
if (line >= 5) {
x = 64;
y -= 5 * 10;
}
display.setCursor(x, y);
display.print(" "); // Print spaces to clear the line
display.setCursor(x, y);
display.print(msg);
display.display();
}
#endif