Wstepna wersja RGB na ESP32

This commit is contained in:
Kamil Siejka
2025-06-19 09:36:03 +02:00
parent abed562c8b
commit 4e1c4ff2f1

View File

@@ -11,7 +11,7 @@ TFT_eSPI tft = TFT_eSPI(); // domyślna konfiguracja z User_Setup.h
// obsługa przycisków zmieniających menu i LED
//160x128
#define Version "0.0.0"
#define Version "0.0.1"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
@@ -162,8 +162,6 @@ void loop() {
}
if (menu_number == 0 ) {//show menu
tft.setTextSize(2);
tft.drawString("GAIN:" + String(gainValue),0, 0);
@@ -177,11 +175,9 @@ void loop() {
delay(100);
}
// //
// show calculated values
if (menu_number == 1 || menu_number == 5 ) {//show calculated values
drawControls();
//tft.setRotation(0);
tft.drawString("Calculated Values",0,0);
tft.drawString("R:" + String(CalcRed),0, 20);
tft.drawString("O:" + String(CalcOrange),0, 39);
@@ -202,163 +198,101 @@ void loop() {
tft.drawString("V:" + String(RawViolet),0, 115);
}
//show relative calculated values graph
if (menu_number == 3 || menu_number == 7 ){
tft.setTextColor(TFT_WHITE, TFT_BLACK);
maxValue = 0.0;
minValue = 0.0;
for (int i = 0; i < 5; i++) {
maxValue = max(maxValue, ReadValues[i]);
}
HeightRed = int((CalcRed / maxValue) * GraphHeight);
HeightOrange = int((CalcOrange / maxValue) * GraphHeight);
HeightYellow = int((CalcYellow / maxValue) * GraphHeight);
HeightGreen = int((CalcGreen / maxValue) * GraphHeight);
HeightBlue = int((CalcBlue / maxValue) * GraphHeight);
HeightViolet = int((CalcViolet / maxValue) * GraphHeight);
for (int i = 0; i < 5; i++) {
maxValue = min(maxValue, ReadValues[i]);
}
tft.fillRect(minValue, 0, 240, maxValue-minValue, TFT_BLACK);
drawControls();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("Relvative Calculated Values",0,0);
drawControls();
tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed+8, GrapWidth, HeightRed, TFT_RED);
tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange+8, GrapWidth, HeightOrange, TFT_ORANGE);
tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow+8, GrapWidth, HeightYellow, TFT_YELLOW);
tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen+8, GrapWidth, HeightGreen, TFT_GREEN);
tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue+8, GrapWidth, HeightBlue, TFT_BLUE);
tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet+8, GrapWidth, HeightViolet, TFT_MAGENTA);
tft.setCursor(1 * GrapWidth -10, 0);
////tft.setRotation(0);
// //show relative calculated values graph
// if (menu_number == 3 || menu_number == 7 ){
// maxValue = 0;
// drawControls();
// ////tft.setRotation(0);
// for (int i = 0; i < 5; i++) {
// maxValue = max(maxValue, ReadValues[i]);
// }
// HeightRed = int((CalcRed / maxValue) * GraphHeight);
// HeightOrange = int((CalcOrange / maxValue) * GraphHeight);
// HeightYellow = int((CalcYellow / maxValue) * GraphHeight);
// HeightGreen = int((CalcGreen / maxValue) * GraphHeight);
// HeightBlue = int((CalcBlue / maxValue) * GraphHeight);
// HeightViolet = int((CalcViolet / maxValue) * GraphHeight);
// tft.setCursor(1 * GrapWidth -10, 10);
// if (HeightRed >25){
// tft.setTextColor(BLACK);
// }
// tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, RED);
// tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, ORANGE);
// tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, YELLOW);
// tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, GREEN);
// tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, BLUE);
// tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, MAGENTA);
// tft.setCursor(1 * GrapWidth -10, 0);
// if (HeightRed > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("R:");
// tft.setCursor(2 * GrapWidth -10, 0);
// if (HeightOrange > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("O:");
// tft.setCursor(3 * GrapWidth -10, 0);
// if (HeightYellow > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("Y:");
// tft.setCursor(4 * GrapWidth -10, 0);
// if (HeightGreen > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("G:");
// tft.setCursor(5 * GrapWidth -10, 0);
// if (HeightBlue > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("B:");
// tft.setCursor(6 * GrapWidth -10, 0);
// if (HeightViolet > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("V:");
// maxValue = 0.0;
// }
tft.setTextColor(TFT_BLACK, TFT_RED);
tft.drawString(" R:",1 * GrapWidth -20, 120);
tft.setTextColor(TFT_BLACK, TFT_ORANGE);
tft.drawString(" O:",2 * GrapWidth -19, 120);
tft.setTextColor(TFT_BLACK, TFT_YELLOW);
tft.drawString(" Y:",3 * GrapWidth -18, 120);
tft.setTextColor(TFT_BLACK, TFT_GREEN);
tft.drawString(" G:",4 * GrapWidth -17, 120);
tft.setTextColor(TFT_BLACK, TFT_BLUE);
tft.drawString(" B:",5 * GrapWidth -16, 120);
tft.setTextColor(TFT_BLACK, TFT_MAGENTA);
tft.drawString(" V:",6 * GrapWidth -15, 120);
maxValue = 0.0;
minValue = 0.0;
}
// //show relative raw data graph
// if (menu_number == 4 || menu_number == 8 ){
// maxValue = 0;
// drawControls();
// ////tft.setRotation(0);
if (menu_number == 4 || menu_number == 8 ){
tft.setTextColor(TFT_WHITE, TFT_BLACK);
maxValue = 0.0;
minValue = 0.0;
for (int i = 0; i < 5; i++) {
maxValue = max(maxValue, ReadValues[i]);
}
for (int i = 0; i < 5; i++) {
minValue = min(minValue, ReadValues[i]);
}
HeightRed = int(((RawRed + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightOrange = int(((RawOrange + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightYellow = int(((RawYellow + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightGreen = int(((RawGreen + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightBlue = int(((RawBlue + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightViolet = int(((RawViolet + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
tft.fillRect(minValue, 0, 240, maxValue-minValue, TFT_BLACK);
drawControls();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("Relvative Raw Values",0,0);
// for (int i = 0; i < 5; i++) {
// maxValue = max(maxValue, ReadValues[i]);
// }
// for (int i = 0; i < 5; i++) {
// minValue = min(minValue, ReadValues[i]);
// }
// HeightRed = int(((RawRed + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
// HeightOrange = int(((RawOrange + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
// HeightYellow = int(((RawYellow + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
// HeightGreen = int(((RawGreen + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
// HeightBlue = int(((RawBlue + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
// HeightViolet = int(((RawViolet + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
// tft.setCursor(1 * GrapWidth -10, 10);
// if (HeightRed >25){
// tft.setTextColor(BLACK);
// }
// tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, RED);
// tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, ORANGE);
// tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, YELLOW);
// tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, GREEN);
// tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, BLUE);
// tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, MAGENTA);
// tft.setCursor(1 * GrapWidth -10, 0);
// if (HeightRed > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("R");
// tft.setCursor(2 * GrapWidth -10, 0);
// if (HeightOrange > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("O");
// tft.setCursor(3 * GrapWidth -10, 0);
// if (HeightYellow > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("Y");
// tft.setCursor(4 * GrapWidth -10, 0);
// if (HeightGreen > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("G");
// tft.setCursor(5 * GrapWidth -10, 0);
// if (HeightBlue > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("B");
// tft.setCursor(6 * GrapWidth -10, 0);
// if (HeightViolet > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("V");
// maxValue = 0.0;
// }
tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed+8, GrapWidth, HeightRed, TFT_RED);
tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange+8, GrapWidth, HeightOrange, TFT_ORANGE);
tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow+8, GrapWidth, HeightYellow, TFT_YELLOW);
tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen+8, GrapWidth, HeightGreen, TFT_GREEN);
tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue+8, GrapWidth, HeightBlue, TFT_BLUE);
tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet+8, GrapWidth, HeightViolet, TFT_MAGENTA);
tft.setTextColor(TFT_BLACK, TFT_RED);
tft.drawString(" R:",1 * GrapWidth -20, 120);
tft.setTextColor(TFT_BLACK, TFT_ORANGE);
tft.drawString(" O:",2 * GrapWidth -19, 120);
tft.setTextColor(TFT_BLACK, TFT_YELLOW);
tft.drawString(" Y:",3 * GrapWidth -18, 120);
tft.setTextColor(TFT_BLACK, TFT_GREEN);
tft.drawString(" G:",4 * GrapWidth -17, 120);
tft.setTextColor(TFT_BLACK, TFT_BLUE);
tft.drawString(" B:",5 * GrapWidth -16, 120);
tft.setTextColor(TFT_BLACK, TFT_MAGENTA);
tft.drawString(" V:",6 * GrapWidth -15, 120);
maxValue = 0.0;
minValue = 0.0;
}
delay(100);
if (menu_number > 4 ) {
@@ -399,25 +333,25 @@ void loop() {
// //data haverest
// RawRed = sensor.getRed();
// RawOrange = sensor.getOrange();
// RawYellow = sensor.getYellow();
// RawGreen = sensor.getGreen();
// RawBlue = sensor.getBlue();
// RawViolet = sensor.getViolet();
//data haverest
RawRed = sensor.getRed();
RawOrange = sensor.getOrange();
RawYellow = sensor.getYellow();
RawGreen = sensor.getGreen();
RawBlue = sensor.getBlue();
RawViolet = sensor.getViolet();
// CalcRed = sensor.getCalibratedRed();
// CalcOrange = sensor.getCalibratedOrange();
// CalcYellow = sensor.getCalibratedYellow();
// CalcGreen = sensor.getCalibratedGreen();
// CalcBlue = sensor.getCalibratedBlue();
// CalcViolet = sensor.getCalibratedViolet();
CalcRed = sensor.getCalibratedRed();
CalcOrange = sensor.getCalibratedOrange();
CalcYellow = sensor.getCalibratedYellow();
CalcGreen = sensor.getCalibratedGreen();
CalcBlue = sensor.getCalibratedBlue();
CalcViolet = sensor.getCalibratedViolet();
// ReadValues[0] = CalcRed;
// ReadValues[1] = CalcOrange;
// ReadValues[2] = CalcYellow;
// ReadValues[3] = CalcGreen;
// ReadValues[4] = CalcBlue;
// ReadValues[5] = CalcViolet;
ReadValues[0] = CalcRed;
ReadValues[1] = CalcOrange;
ReadValues[2] = CalcYellow;
ReadValues[3] = CalcGreen;
ReadValues[4] = CalcBlue;
ReadValues[5] = CalcViolet;
}