character can now be drawn and shifted
This commit is contained in:
@@ -12,11 +12,13 @@
|
||||
#define PIN 12
|
||||
|
||||
#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);
|
||||
|
||||
unsigned char saved_images_count = 0;
|
||||
unsigned short horizontal_cursor1_position = 0;
|
||||
|
||||
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) {
|
||||
@@ -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_y = row + offset_y;
|
||||
|
||||
if (pixel_x >= 0 && pixel_x < PANEL_PIXEL_COUNT &&
|
||||
pixel_y >= 0 && pixel_y < PANEL_PIXEL_COUNT) {
|
||||
if (pixel_x >= 0 && pixel_x < NUMPIXELS &&
|
||||
pixel_y >= 0 && pixel_y < NUMPIXELS) {
|
||||
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 col = 0; col < 5; 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;
|
||||
|
||||
if (pixel_x >= 0 && pixel_x < PANEL_PIXEL_COUNT &&
|
||||
pixel_y >= 0 && pixel_y < PANEL_PIXEL_COUNT) {
|
||||
if (pixel_x >= 0 && pixel_x < NUMPIXELS &&
|
||||
pixel_y >= 0 && pixel_y < NUMPIXELS) {
|
||||
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() {
|
||||
Serial.begin(115200);
|
||||
|
||||
pixels.begin();
|
||||
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();
|
||||
start_server();
|
||||
|
||||
Reference in New Issue
Block a user