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