Replies: 1 comment 1 reply
-
|
it seems that the problem is not with the code, but with the Proteus simulator |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
-
Good afternoon, friends, please tell me what the problem might be in drawing lines at the specified coordinates. I looked at an example from the library's root directory, the AnalogClock. project, and it only has examples of drawing straight lines. However, the issue lies in the fact that I am drawing the interface of analog instruments, and I have tried several GFX libraries, but the Arduino GFX library seems to meet my requirements better in terms of drawing circular arcs. I was able to draw the arcs without any problems, set the length using the specified angles, width, and colors, and it works in the code and displays on the screen. However, I was unable to draw a straight line using several methods and through drawlLne(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color and through writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color? the result is the same, the line is not drawn on the display. Yes, I want to add that it is not misleading and is tested on virtual hardware in the Proteus_8_Professional_8.5 program. in the test code, I simply created arcs, assigned coordinates to them, and set their color. I then attempted to draw arrows, but unfortunately, nothing was displayed on the virtual screen other than the arcs. I tried to apply this line at the end of the drawing code for one of the devices, but the result was negative. I also tried to draw using the added variables, tft->drawLine(TEMP_CENTER_X, TEMP_CENTER_Y, TEMP_CENTER_X - TEMP_NEEDLE_LENGTH, TEMP_CENTER_Y, COLOR_YELLOW); but the result was the same. I tried to assign a value in the setup for the drawHUM_NEEDLE() line, and in the loop, I wrote void drawHUM_NEEDLE(){
tft->drawLine(TEMP_CENTER_X, TEMP_CENTER_Y, TEMP_CENTER_X - TEMP_NEEDLE_LENGTH, TEMP_CENTER_Y, COLOR_YELLOW); }
and again the result is negative, the line is not drawn., please tell me where there is an error, and what I am doing wrong. Thanks in advance.
The sample code is attached
`// --- БЛОК 1: ЗАГОЛОВОК И ОПРЕДЕЛЕНИЯ ---
// 1.1 Подключаем графическую библиотеку для дисплея
#include <Arduino_GFX_Library.h>
// 1.2 Определяем пины подключения дисплея
#define TFT_CS 10 // Выбор кристалла (Chip Select)
#define TFT_DC 9 // Команда/Данные (Data/Command)
#define TFT_RST 8 // Сброс (Reset)
// --- СОЗДАНИЕ ОБЪЕКТОВ ---
//#define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
#if defined(DISPLAY_DEV_KIT)
Arduino_GFX tft = create_default_Arduino_GFX();
#else / !defined(DISPLAY_DEV_KIT) */
Arduino_DataBus *bus = create_default_Arduino_DataBus();
Arduino_GFX tft = new Arduino_ILI9341(bus, DF_GFX_RST, 0 / rotation /, false / IPS /);
#endif / !defined(DISPLAY_DEV_KIT) */
// 1.4 Задаем константы для центров приборов (координаты оснований стрелок)
#define TEMP_CENTER_X 203
#define TEMP_CENTER_Y 157
#define HUM_CENTER_X 88
#define HUM_CENTER_Y 157
// 1.5 Задаем длину стрелок в пикселях
#define TEMP_NEEDLE_LENGTH 77
#define HUM_NEEDLE_LENGTH 63
// 1.6 Задаем цвета в формате RGB565
#define COLOR_BACKGROUND tft->color565(0, 0, 0) // Черный
#define COLOR_RED tft->color565(255, 0, 0) // Красный
#define COLOR_YELLOW tft->color565(255, 255, 0) // Желтый
#define COLOR_GREEN tft->color565(0, 255, 0) // Зеленый
#define COLOR_BLUE tft->color565(0, 0, 255) // Синий
#define COLOR_GRAY tft->color565(128,128,128) // Серый
#define COLOR_WHITE tft->color565(255, 255, 255)// Белый
// --- БЛОК 2: ФУНКЦИИ SETUP И LOOP ---
// 2.1 Блок setup() выполняется один раз при запуске
void setup() {
// Инициализируем дисплей (подаем питание, настраиваем шину)
tft->begin();
// Устанавливаем ориентацию экрана. '1' - горизонтальный режим.
tft->setRotation(1);
// Заливаем весь экран черным цветом для очистки
tft->fillScreen(COLOR_BACKGROUND);
// --- ВЫЗЫВАЕМ ФУНКЦИИ ОТРИСОВКИ ПРИБОРОВ ---
// Рисуем шкалу влажности в центре (88, 157)
drawHumidityScale();
// Рисуем шкалу температуры в центре (203, 157)
drawTempScale();
}
// 2.2 Блок loop() выполняется бесконечно
void loop() {
// Так как интерфейс статичный и отрисован в setup(),
// здесь ничего делать не нужно.
}
// --- БЛОК 3: ШКАЛА ВЛАЖНОСТИ (ВЕРСИЯ 2 - С ИСПОЛЬЗОВАНИЕМ ПЕРЕМЕННЫХ) ---
void drawHumidityScale() {
int centerX = HUM_CENTER_X;
int centerY = HUM_CENTER_Y;
// --- ТВОЯ СТРУКТУРА РАСЧЕТА РАДИУСОВ ---
int baseRadius = HUM_NEEDLE_LENGTH;
int outerRadius = baseRadius + 8; // Внешний радиус серой дуги
int innerRadius = baseRadius + 4; // Внутренний радиус серой дуги
// --- ОТРИСОВКА СЕРОЙ ОКАНТОВКИ ---
// Углы для влажности: от 180° до 360°
tft->fillArc(centerX, centerY, outerRadius, innerRadius, 180, 270, COLOR_GRAY);
// --- ОТРИСОВКА ЦВЕТНЫХ СЕКТОРОВ ---
int colorOuterRadius = outerRadius - 5;
int colorInnerRadius = innerRadius - 5;
// --- РАСЧЕТ УГЛОВ ДЛЯ ВЛАЖНОСТИ (22,5 градусов на сектор) ---
// Красный сектор (75-100%)
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 180, 202.5, COLOR_RED);
// Желтый сектор (50-75%)
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 202.5, 225, COLOR_YELLOW);
// Зеленый сектор (25-50%)
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 225, 247.5, COLOR_GREEN);
// Синий сектор (0-25%)
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 247.5, 270, COLOR_BLUE);
}
// --- БЛОК 4: ШКАЛА ТЕМПЕРАТУРЫ ---
void drawTempScale() {
int centerX = TEMP_CENTER_X;
int centerY = TEMP_CENTER_Y;
// --- ТВОИ РАСЧЕТЫ РАДИУСОВ ---
int baseRadius = TEMP_NEEDLE_LENGTH;
int outerRadius = baseRadius + 8;
int innerRadius = baseRadius + 4;
// --- ОТРИСОВКА СЕРОЙ ОКАНТОВКИ ---
// Используем твой рабочий синтаксис углов: от 180 до 360 градусов
tft->fillArc(centerX, centerY, outerRadius, innerRadius, 180, 360, COLOR_GRAY);
// --- ОТРИСОВКА ЦВЕТНЫХ СЕКТОРОВ ---
int colorOuterRadius = outerRadius - 5;
int colorInnerRadius = innerRadius - 5;
// --- ВЕРНЫЙ РАСЧЕТ УГЛОВ ---
// Вся шкала: от 180 до 360 градусов. Итого: 180 градусов.
// Делим на 4 сектора: 180 / 4 = 45 градусов на сектор.
// Синий сектор (0% - 25%) - Начинаем с 180°
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 180, 225, COLOR_BLUE);
// Зеленый сектор (25% - 50%) - Следующие 45 градусов
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 225, 270, COLOR_GREEN);
// Желтый сектор (50% - 75%)
tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 270, 315, COLOR_YELLOW);
// Красный сектор (75% - 100%) - Заканчиваем на 360°

tft->fillArc(centerX, centerY, colorOuterRadius, colorInnerRadius, 315, 360, COLOR_RED);
}
`
Beta Was this translation helpful? Give feedback.
All reactions