character can now be drawn and shifted

This commit is contained in:
2026-01-27 11:24:12 +01:00
parent c8a8f31477
commit 4fa11a57db
2 changed files with 68 additions and 14 deletions
+2 -2
View File
@@ -401,13 +401,13 @@ constexpr bool font7x5[95][7][5] = {
}, },
// I (ASCII 73) // I (ASCII 73)
{ {
{false, true, true, true, false}, {true, true, true, true, true},
{false, false, true, false, false}, {false, false, true, false, false},
{false, false, true, false, false}, {false, false, true, false, false},
{false, false, true, false, false}, {false, false, true, false, false},
{false, false, true, false, false}, {false, false, true, false, false},
{false, false, true, false, false}, {false, false, true, false, false},
{false, true, true, true, false} {true, true, true, true, true}
}, },
// J (ASCII 74) // J (ASCII 74)
{ {
+66 -12
View File
@@ -12,11 +12,13 @@
#define PIN 12 #define PIN 12
#define PANEL_PIXEL_COUNT 16 #define PANEL_PIXEL_COUNT 16
#define NUMPIXELS PANEL_PIXEL_COUNT*PANEL_PIXEL_COUNT #define PANEL_COUNT 3
#define NUMPIXELS PANEL_PIXEL_COUNT*PANEL_PIXEL_COUNT*PANEL_COUNT
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
unsigned char saved_images_count = 0; unsigned char saved_images_count = 0;
unsigned short horizontal_cursor1_position = 0;
uint32_t saved_imaged[12][16][16] = { uint32_t saved_imaged[12][16][16] = {
{ {
@@ -72,13 +74,21 @@ uint32_t saved_imaged[12][16][16] = {
}; };
void setPixel(unsigned short y, unsigned short x, uint32_t color) void setPixel(unsigned short x, unsigned short y, uint32_t color)
{ {
if (y % 2 == 1) if (x % 2 == 1)
{ {
x = PANEL_PIXEL_COUNT - 1 - x; y = PANEL_PIXEL_COUNT - 1 - y;
} }
pixels.setPixelColor(x + (y * PANEL_PIXEL_COUNT), color); pixels.setPixelColor(y + (x * PANEL_PIXEL_COUNT), color);
}
uint32_t getPixelColor(unsigned short x, unsigned short y) {
if (x % 2 == 1)
{
y = PANEL_PIXEL_COUNT - 1 - y;
}
return pixels.getPixelColor(y + (x * PANEL_PIXEL_COUNT));
} }
void drawImageFromSaved(unsigned short offset_x, unsigned short offset_y, unsigned char i) { void drawImageFromSaved(unsigned short offset_x, unsigned short offset_y, unsigned char i) {
@@ -91,37 +101,81 @@ void drawImageFromSaved(unsigned short offset_x, unsigned short offset_y, unsign
unsigned short pixel_x = col + offset_x; unsigned short pixel_x = col + offset_x;
unsigned short pixel_y = row + offset_y; unsigned short pixel_y = row + offset_y;
if (pixel_x >= 0 && pixel_x < PANEL_PIXEL_COUNT && if (pixel_x >= 0 && pixel_x < NUMPIXELS &&
pixel_y >= 0 && pixel_y < PANEL_PIXEL_COUNT) { pixel_y >= 0 && pixel_y < NUMPIXELS) {
setPixel(pixel_x, pixel_y, px_color); setPixel(pixel_x, pixel_y, px_color);
} }
} }
} }
} }
void drawCharacter(const bool (*character)[5], unsigned char offset_x, unsigned char offset_y, uint32_t color) { void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, unsigned short offset_x, unsigned short offset_y, uint32_t color) {
for (unsigned char row = 0; row < 7; row++) { for (unsigned char row = 0; row < 7; row++) {
for (unsigned char col = 0; col < 5; col++) { for (unsigned char col = 0; col < 5; col++) {
if (character[row][col]) { if (character[row][col]) {
unsigned short pixel_x = col + offset_x; unsigned short pixel_x = col + offset_x + horizontal_cursor1_position;
unsigned short pixel_y = row + offset_y; unsigned short pixel_y = row + offset_y;
if (pixel_x >= 0 && pixel_x < PANEL_PIXEL_COUNT && if (pixel_x >= 0 && pixel_x < NUMPIXELS &&
pixel_y >= 0 && pixel_y < PANEL_PIXEL_COUNT) { pixel_y >= 0 && pixel_y < NUMPIXELS) {
setPixel(pixel_x, pixel_y, color); setPixel(pixel_x, pixel_y, color);
} }
} }
} }
} }
horizontal_cursor1_position += width + offset_x + 1;
} }
void fillPixels(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, uint32_t color)
{
if (x1 > x2) {
unsigned short tmp = x1; x1 = x2; x2 = tmp;
}
if (y1 > y2) {
unsigned short tmp = y1; y1 = y2; y2 = tmp;
}
unsigned short width = (unsigned short)(x2 - x1 + 1);
unsigned short height = (unsigned short)(y2 - y1 + 1);
for (unsigned short i = 0; i < height; i++) {
for (unsigned short j = 0; j < width; j++) {
setPixel(x1 + j, y1 + i, color);
}
}
}
void shiftGivenRectangle(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2, unsigned char shiftBy) {
if (x1 > x2) {
unsigned short tmp = x1; x1 = x2; x2 = tmp;
}
if (y1 > y2) {
unsigned short tmp = y1; y1 = y2; y2 = tmp;
}
unsigned short width = (unsigned short)(x2 - x1 + 1);
unsigned short height = (unsigned short)(y2 - y1 + 1);
for (unsigned short i = 0; i < height; i++) {
for (unsigned short j = 0; j < width + shiftBy; j++) {
setPixel(x1 + j - shiftBy, y1 + i, getPixelColor(x1 + j, y1 + i));
setPixel(x1 + j, y1 + i, 0x00000000);
}
}
}
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
pixels.begin(); pixels.begin();
pixels.clear(); pixels.clear();
drawCharacter(font7x5[0], 7, 5, 0xFFFFFFFF); drawCharacter(font7x5['P' - '!'], 7, 5, 4, 0, 0x00030100);
drawCharacter(font7x5['T' - '!'], 7, 5, 0, 0, 0x00030100);
drawCharacter(font7x5['I' - '!'], 7, 5, 0, 0, 0x00030100);
shiftGivenRectangle(0, 0, 19, 7, 3);
pixels.show(); pixels.show();
start_server(); start_server();