From 73a33868bcc9964356f94e2fce3651de98cc98e8 Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 22 Nov 2025 00:16:31 +0300 Subject: [PATCH] display ssd1306 2 init --- .DS_Store | Bin 6148 -> 8196 bytes .vscode/c_cpp_properties.json | 3 +- .vscode/settings.json | 11 ++++- pipboy-setup.sh | 2 +- pipboyIO/display.cpp | 75 ++++++++++++++++++++++++++++++++++ pipboyIO/display.h | 18 ++++++++ pipboyIO/pipboyIO.ino | 37 ++++++++++++++++- 7 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 pipboyIO/display.cpp create mode 100644 pipboyIO/display.h diff --git a/.DS_Store b/.DS_Store index 1786a1936e43d2a829f52ea301de4222c8a687a1..9ab578760f57007be402e60ea0cdce8db4199d56 100644 GIT binary patch delta 753 zcmYLHOH30{6rJ;?g&8{9se%;rMJQ-A0;w7T;wOB95fzFSLP3;Fd80fmQ|L@V{G=>! zgVCgEj4O@Cl`c%Q!Ho;IXyQh3N z(`>IGIHqJ@2UTBoW=poI7M`d5FT{L}v@Sj@m89%~2cDebS=-qaPbA}lAV%ZU32s{9 z@COjl<1HzbQ@7sHY*j%2xq!s z@$+0y4QuAOZZK|K7@XtGni!hpCXXld0YjV80K$^epxYNH{GKQnEbLXshS(u zq=c1$i`-zcYP!sRrI`*Uw78y-Rptt{Ds6OVR!^BcX~^mcmprUg(Aao#YARz7Y056y zLA&TVNB5*=T9IkpaC%yCeMfEIh&iF9^vIl{r;05dx7jh(U*MgjZpN)-!D;_TUx?CS zr(6ePg(0egRel}||{$QPWNhJxAsv{&s8b~8)A}yqqw2_0Pk3>j}Xk?Nk$+W$E z_91XlI9tRbkoo)8`>{N+8lh$2aL0cV+o+?aAZzvR6} IvI|Rp0evpM5dZ)H delta 104 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$jH1gU^g=(^JE@@_nY%Xc$gQn qb8rYU162Tl05_0u1u5QG_?>w&zl +#include +#include +#include + +//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 + +#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(); \ No newline at end of file diff --git a/pipboyIO/pipboyIO.ino b/pipboyIO/pipboyIO.ino index f80517a..bba03cb 100644 --- a/pipboyIO/pipboyIO.ino +++ b/pipboyIO/pipboyIO.ino @@ -2,6 +2,7 @@ #include #include #include +#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); +} \ No newline at end of file