DIYLAB
Well-known member
Hello, everyone,
for a project i am developing a VU-meter which imitates the original analog displays on a 2.8" display with ILI9341 controller.
The SPI clock is 40MHz and the Teensy 4.0 with 600MHz is used.
A frame buffer is used and as data I take automatically generated values between 0 and 100 and back.
The main loop should be run through as fast as possible for testing.
Unfortunately the needles don't move nearly as fast as hoped ;o(
And the lower part of the Peak-LED is cut off and I don't know why yet.
What am I doing wrong?
And how do I get more speed of the needles?
The project is pinned up here.
Best regards
Bruno
for a project i am developing a VU-meter which imitates the original analog displays on a 2.8" display with ILI9341 controller.
The SPI clock is 40MHz and the Teensy 4.0 with 600MHz is used.
A frame buffer is used and as data I take automatically generated values between 0 and 100 and back.
The main loop should be run through as fast as possible for testing.
Unfortunately the needles don't move nearly as fast as hoped ;o(
And the lower part of the Peak-LED is cut off and I don't know why yet.
What am I doing wrong?
And how do I get more speed of the needles?
The project is pinned up here.
Best regards
Bruno
Code:
#include "SPI.h"
#include <ILI9341_t3n.h>
#include "analog_leftside.c"
#include "analog_leftside_led.c"
#include "analog_rightside.c"
#include "analog_rightside_led.c"
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
ILI9341_t3n tft = ILI9341_t3n(TFT_CS, TFT_DC, TFT_RST);
int16_t leftNeedleRectMinX, rightNeedleRectMinX;
int16_t leftNeedleRectMinY, rightNeedleRectMinY;
int16_t leftNeedleRectMaxX, rightNeedleRectMaxX;
int16_t leftNeedleRectMaxY, rightNeedleRectMaxY;
int16_t workCounter;
uint8_t pastLeft, pastRight;
boolean direction;
void setup() {
tft.begin(40000000);
tft.useFrameBuffer(true);
tft.setRotation(2);
tft.fillScreen(ILI9341_WHITE);
tft.writeRect(0, 0, 120, 320, (uint16_t*)analog_leftside);
tft.writeRect(120, 0, 120, 320, (uint16_t*)analog_rightside);
tft.updateScreen();
}
void loop(void) {
(!direction) ? workCounter++ : workCounter--;
if (workCounter > 100) {
workCounter = 100;
direction = true;
}
if (workCounter < 0) {
workCounter = 0;
direction = false;
}
drawNeedleLeft(workCounter);
drawNeedleRight(workCounter);
}
void drawNeedleLeft(uint8_t percent) {
if (percent != pastLeft) {
pastLeft = percent;
double scale = map(percent, 0, 100, 57, 123);
int16_t x0 = -115; // Start-X
int16_t y0 = 160; // Start-Y
int16_t x1 = -115 + 193 * sin(scale * 0.0174532925); // End-X
int16_t y1 = 160 + 193 * cos(scale * 0.0174532925); // End-Y
int16_t left_min_x = leftNeedleRectMinX;
int16_t left_min_y = leftNeedleRectMinY;
int16_t left_max_x = leftNeedleRectMaxX;
int16_t left_max_y = leftNeedleRectMaxY;
leftNeedleRectMinX = min(x0, x1);
leftNeedleRectMinY = min(y0, y1);
leftNeedleRectMaxX = max(x0, x1);
leftNeedleRectMaxY = max(y0, y1);
left_min_x = min(left_min_x, leftNeedleRectMinX);
left_min_y = min(left_min_y, leftNeedleRectMinY);
left_max_x = max(left_max_x, leftNeedleRectMaxX);
left_max_y = max(left_max_y, leftNeedleRectMaxY);
tft.setClipRect(0, 0, 120, 320);
tft.writeRect(0, 0, 120, 320, (percent >= 79) ? (uint16_t*)analog_leftside_led : (uint16_t*)analog_leftside);
tft.setClipRect(left_min_x, left_min_y, left_max_x - left_min_x + 1, left_max_y - left_min_y + 1);
tft.drawLine(x0, y0, x1, y1, ILI9341_BLACK);
tft.updateScreen();
}
}
void drawNeedleRight(uint8_t percent) {
if (percent != pastRight) {
pastRight = percent;
double scale = map(100 - percent, 0, 100, 57, 123);
int16_t x0 = 355; // Start-X
int16_t y0 = 160; // Start-Y
int16_t x1 = 355 - 193 * sin(scale * 0.0174532925); // End-X
int16_t y1 = 160 - 193 * cos(scale * 0.0174532925); // End-Y
int16_t right_min_x = rightNeedleRectMinX;
int16_t right_min_y = rightNeedleRectMinY;
int16_t right_max_x = rightNeedleRectMaxX;
int16_t right_max_y = rightNeedleRectMaxY;
rightNeedleRectMinX = min(x0, x1);
rightNeedleRectMinY = min(y0, y1);
rightNeedleRectMaxX = max(x0, x1);
rightNeedleRectMaxY = max(y0, y1);
right_min_x = min(right_min_x, rightNeedleRectMinX);
right_min_y = min(right_min_y, rightNeedleRectMinY);
right_max_x = max(right_max_x, rightNeedleRectMaxX);
right_max_y = max(right_max_y, rightNeedleRectMaxY);
tft.setClipRect(120, 0, 120, 320);
tft.writeRect(120, 0, 120, 320, (percent >= 79) ? (uint16_t*)analog_rightside_led : (uint16_t*)analog_rightside);
tft.setClipRect(right_min_x, right_min_y, right_max_x - right_min_x + 1, right_max_y - right_min_y + 1);
tft.drawLine(x0, y0, x1, y1, ILI9341_BLACK);
tft.updateScreen();
}
}
Attachments
Last edited: