Files
pti-ledy/ledy.ino
T
2026-01-27 18:55:21 +01:00

116 lines
2.9 KiB
Arduino

#include <Adafruit_NeoPixel.h>
#include <WiFi.h>
#include <WebServer.h>
#include <ArduinoJson.h>
#include "index.h"
#include "fonts.h"
#include "cursor.h"
#include "lowLevel.ino"
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 12
#define PANEL_PIXEL_COUNT 16
#define PANEL_COUNT 3
#define NUMPIXELS PANEL_PIXEL_COUNT*PANEL_PIXEL_COUNT*PANEL_COUNT
#define PANEL_MAX_X PANEL_PIXEL_COUNT * PANEL_COUNT - 1
#define PANEL_MAX_Y PANEL_PIXEL_COUNT - 1
#define TEXT_MAX_LENGTH 64
#define SCROLLABLE_TEXT_MAX_COUNT 4
#define SMALL_TEXT_HEIGHT 7
#define SMALL_TEXT_WIDTH 5
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
Text scrollable_texts[SCROLLABLE_TEXT_MAX_COUNT];
void addLeftScrollableTextOnScreen(char text[TEXT_MAX_LENGTH], uint32_t color = 0x00010101, bool is_small = true, unsigned short pos_x = nullptr, unsigned short pos_y)
{
unsigned char character_index = 0;
for (unsigned char i = 0; i < SCROLLABLE_TEXT_MAX_COUNT; i++)
{
if (scrollable_texts[i].deleted)
{
scrollable_texts[i].deleted = false;
character_index = i;
break;
}
}
if (pos_x == nullptr)
{
for (unsigned char i = 0; true; i++)
{
if (!text[i])
{
pos_x = PANEL_MAX_X - ((characterSize.width + 1) * i);
}
}
}
for (unsigned char i = 0; i < TEXT_MAX_LENGTH; i++)
{
scrollable_texts[character_index].content[i] = text[i];
if (!text[i])
{
scrollable_texts[character_index].character_count = i;
break;
}
}
scrollable_texts[character_index].color = color;
scrollable_texts[character_index].pos_x = pos_x;
scrollable_texts[character_index].pos_y = pos_y;
if (is_small)
{
scrollable_texts[character_index].characterSize.height = SMALL_TEXT_HEIGHT;
scrollable_texts[character_index].characterSize.width = SMALL_TEXT_WIDTH;
}
}
void drawGivenLeftScrollableText(unsigned char index, Cursor (*used_cursor))
{
if (scrollable_texts[index].deleted)
{
return;
}
for (unsigned char i = 0; i < scrollable_texts[index].character_count; i++)
{
if (scrollable_texts[index].is_small)
{
for (unsigned char char_i = 0; char_i < scrollable_texts[index].character_count; char_i++)
{
used_cursor.x = scrollable_texts[index].pos_x;
used_cursor.y = scrollable_texts[index].pos_y;
drawCharacter(font7x5[scrollable_texts[index].content[char_i] - '!'], 7, 5, scrollable_texts[index].color, used_cursor);
}
}
}
}
void setup()
{
Serial.begin(115200);
pixels.begin();
pixels.clear();
addLeftScrollableTextOnScreen("Its alive!");
pixels.show();
start_server();
}
void loop()
{
shiftGivenRectangle(0, 0, 19, 7, 1);
pixels.show();
handle_server();
}