Browse Source

display ssd1306 2 init

main
gsd 6 months ago
parent
commit
73a33868bc
  1. BIN
      .DS_Store
  2. 3
      .vscode/c_cpp_properties.json
  3. 11
      .vscode/settings.json
  4. 2
      pipboy-setup.sh
  5. 75
      pipboyIO/display.cpp
  6. 18
      pipboyIO/display.h
  7. 37
      pipboyIO/pipboyIO.ino

BIN
.DS_Store

Binary file not shown.

3
.vscode/c_cpp_properties.json

@ -3,7 +3,8 @@
{
"name": "Mac",
"includePath": [
"/Users/gsd/Library/Arduino15/packages/**"
"/Users/gsd/Library/Arduino15/packages/**",
"/Users/gsd/Documents/Arduino/libraries/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",

11
.vscode/settings.json

@ -11,6 +11,15 @@
"unordered_map": "cpp",
"vector": "cpp",
"ostream": "cpp",
"map": "cpp"
"map": "cpp",
"__tree": "cpp",
"deque": "cpp",
"list": "cpp",
"regex": "cpp",
"set": "cpp",
"span": "cpp",
"unordered_set": "cpp",
"format": "cpp",
"text_encoding": "cpp"
}
}

2
pipboy-setup.sh

@ -67,7 +67,7 @@ xset -dpms
xset s noblank
# Запуск Chromium
exec chromium-browser --no-memcheck --noerrdialogs --disable-infobars --disable-background-timer-throttling --disable-renderer-backgrounding --disable-backgrounding-occluded-windows --check-for-update-interval=31536000 --no-first-run --kiosk http://127.0.0.1
exec chromium-browser --no-memcheck --noerrdialogs --disable-infobars --disable-background-timer-throttling --disable-renderer-backgrounding --disable-backgrounding-occluded-windows --check-for-update-interval=31536000 --no-first-run --incognito --kiosk http://127.0.0.1
EOT
#uart

75
pipboyIO/display.cpp

@ -0,0 +1,75 @@
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <display.h>
//Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);
void initDisplay() {
/*Wire.begin(D1_I2C_SDA, D1_I2C_SCL);
if(!display1.begin(SSD1306_EXTERNALVCC, DISPLAY_I2C_ADDRESS)) {
Serial.println("SSD1306 #1 allocation failed");
for(;;);
}*/
Wire1.begin(D2_I2C_SDA, D2_I2C_SCL);
if(!display2.begin(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDRESS)) {
Serial.println("SSD1306 #2 allocation failed");
for(;;);
}
//display1.clearDisplay();
//Serial.println("start display 2");
display2.clearDisplay();
for (int x = 0; x < 128; x ++) {
for (int y = 0; y < 64; y++) {
display2.drawPixel(x, y, SSD1306_WHITE);
}
}
display2.display();
//Serial.println("start display 2 test success");
}
void drawPoint(int displayId, int x, int y) {
switch (displayId)
{
case 1:
//display1.clearDisplay();
//display1.drawPixel(x, y, SSD1306_WHITE);
break;
case 2:
display2.clearDisplay();
display2Border();
display2.drawPixel(x, y, SSD1306_WHITE);
display2.display();
break;
default:
break;
}
}
const int16_t borders[][2] = {
{20, 59},
{20, 30},
{29, 15},
{40, 3},
{45, 1},
{65, 0},
{80, 1},
{91, 3},
{103, 15},
{110, 30},
{110, 59}
};
const int borderSize = sizeof(borders) / sizeof(borders[0]);
void display2Border() {
int x = 0;
int y = 1;
for (int i = 1; i <borderSize; i++) {
display2.drawLine(borders[i-1][x], borders[i-1][y], borders[i][x], borders[i][y], WHITE);
}
display2.drawLine(borders[borderSize-1][x], borders[borderSize-1][y], borders[0][x], borders[0][y], WHITE);
}

18
pipboyIO/display.h

@ -0,0 +1,18 @@
#include <Adafruit_SSD1306.h>
#define DISPLAY_I2C_ADDRESS 0x3C
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define D1_I2C_SDA 21
#define D1_I2C_SCL 5
#define D2_I2C_SDA 19 //19
#define D2_I2C_SCL 18 //18
//Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
//Adafruit_SSD1306 display2(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire1, -1);
void initDisplay();
void drawPoint(int displayId, int x, int y);
void display2Border();

37
pipboyIO/pipboyIO.ino

@ -2,6 +2,7 @@
#include <arduino.h>
#include <esp32-hal-adc.h>
#include <HardwareSerial.h>
#include "display.h"
const int input[] = {};
long inputCurrentValue[] = {0, 0, 0, 0, 0, 0, 0, 0};
@ -12,10 +13,12 @@ const int buttonInput[2] = {36,39};
int buttonLastState[2] = {HIGH, HIGH};
int buttonCurrentState[2];
String inputBuffer = "";
#define RXD2 (16)
#define TXD2 (17)
//#define DEBUGIO
#define DEBUGIO
void setup() {
#ifdef DEBUGIO
@ -25,6 +28,7 @@ void setup() {
#endif
setupEncoder();
initDisplay();
pinMode(buttonInput[0], INPUT);
@ -84,6 +88,37 @@ void loop() {
setOldencoderCount(enc, getEncoderCount(enc));
}
}
//читаем кал
while (Serial.available() > 0) {
char chr = Serial.read();
if (chr == '\n') {
processInput(inputBuffer);
inputBuffer = "";
} else {
inputBuffer += chr;
}
}
delay(50);
}
void processInput(String input) {
input.trim();
int firstSpace = input.indexOf(' ');
int secondSpace = input.indexOf(' ', firstSpace + 1);
if (firstSpace == -1 || secondSpace == -1) {
return;
}
String n1 = input.substring(0, firstSpace);
String n2 = input.substring(firstSpace + 1, secondSpace);
String n3 = input.substring(secondSpace + 1);
int displayId = n1.toInt();
int x = n2.toInt();
int y = n3.toInt();
drawPoint(displayId, x, y);
}
Loading…
Cancel
Save