Ukończona wersja 1.1.0

Mednu:
0 - Menu
1 - Calculated Values
2 - Raw Values
3 - Relative Calculated Values
4 - Relative Raw Values

5-8 włączony LED
This commit is contained in:
Kamil Siejka
2024-11-26 15:47:11 +01:00
parent 84ada05193
commit bed83a7a97

View File

@@ -21,14 +21,14 @@
// obsługa przycisków zmieniających gain
//obsługa włączania/wyłączania LED
#define Version "1.0.1"
#define Version "1.1.0"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "AS726X.h"
#define Btn1 8 //on board: 8 menu
#define Btn2 9 //on board: 9 gain
#define Btn2 8 //on board: 8 menu
#define Btn1 9 //on board: 9 gain
AS726X sensor;
Adafruit_SSD1306 display(4);
@@ -54,16 +54,16 @@ int HeightViolet = 0;
byte gain = 3; // values: 0,1,2,3
float gainValue = 64;
int menu_number = 3; // values:0 menu 1,2,3 bez led, 4,5,6 z LED
int menu_number = 0; // values:0 menu 1,2,3 bez led, 4,5,6 z LED
int LedPower = 0;
int GraphHeight = 32;
int GrapWidth = 20;
float ReadValues[6] = {0, 0, 0, 0, 0, 0};
float maxValue = 0.0;
float test_vle = 1.0;
char FloatInChar[20];
char ChValue[20];
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
@@ -75,7 +75,7 @@ void setup() {
display.setCursor(0, 10);
display.println(Version);
display.display();
delay(500);
delay(1000);
Wire.begin();
Serial.begin(115200);
display.clearDisplay();
@@ -94,6 +94,16 @@ void loop() {
//roation 2 -tego nie do gory nogami
//rotation 3 pod wyswietlanie listy wartosci
//menu change
if (digitalRead(Btn2) == 0) {
if (menu_number < 8) {
menu_number = menu_number + 1;
} else {
menu_number = 0;
}
}
if (menu_number > 4 ) {
LedPower = 1;
@@ -108,7 +118,6 @@ void loop() {
sensor.disableBulb();
sensor.takeMeasurements();
}
sensor.takeMeasurements();
//gain change
if (digitalRead(Btn1) == 0) {
if (gain < 3) {
@@ -131,14 +140,6 @@ void loop() {
gainValue = 64;
}
//gain change//menu change
if (digitalRead(Btn2) == 0) {
if (menu_number < 8) {
menu_number = menu_number + 1;
} else {
menu_number = 0;
}
}
//data haverest
RawRed = sensor.getRed();
@@ -163,102 +164,102 @@ void loop() {
ReadValues[5] = CalcViolet;
if (menu_number == 0 || menu_number != 1 || menu_number != 2 || menu_number != 3) {//pokaż menu konfiguracyjne
if (menu_number == 0 ) {//show menu
drawControls();
display.setCursor(0, 0);
display.println("GAIN");
display.setCursor(3, 8);
display.println(gainValue, 1);
display.setCursor(32, 0);
display.println("LED");
display.setCursor(33, 8);
display.println(LedPower);
display.setCursor(60, 0);
display.println("BTN1");
display.setCursor(63, 8);
display.println(digitalRead(Btn1));
display.setCursor(90, 0);
display.println("BTN2");
display.setCursor(93, 8);
display.println(digitalRead(Btn2));
display.setCursor(110, 8);
display.println(menu_number);
display.println(gainValue, 1);
display.setCursor(64, 0);
display.println("LED: 5-8");
display.setCursor(0, 8);
display.println("0:Menu 1:Calculated");
display.setCursor(0, 16);
display.println("menu; calc; raw");
display.println("2:Raw 3:Reltive Graph");
display.setCursor(0, 24);
display.println("rltive grph;calc grph");
display.println("4:Calculated Graph");
}
//
if (menu_number == 1 || menu_number == 4 ) {//pokaż wartości przeliczone
if (menu_number == 1 || menu_number == 5 ) {//show calculated values
drawControls();
display.setRotation(0);
display.setCursor(0, 0);
display.println("R");
display.setCursor((GrapWidth), 0);
display.println("O");
display.setCursor((GrapWidth) * 2, 0);
display.println("Y");
display.setCursor((GrapWidth) * 3, 0);
display.println("G");
display.setCursor((GrapWidth) * 4, 0);
display.println("B");
display.setCursor((GrapWidth) * 5, 0);
display.println("V");
display.setCursor(0, 25);
display.println("R:");
display.setCursor((GrapWidth), 25);
display.println("O:");
display.setCursor((GrapWidth) * 2, 25);
display.println("Y:");
display.setCursor((GrapWidth) * 3, 25);
display.println("G:");
display.setCursor((GrapWidth) * 4, 25);
display.println("B:");
display.setCursor((GrapWidth) * 5, 25);
display.println("V:");
display.setRotation(3);
display.setCursor(0, 10);
display.println(CalcRed, 1);
display.setCursor(0, (GrapWidth * 1) + 10);
display.println(CalcOrange, 1);
display.setCursor(0, (GrapWidth * 2) + 10);
display.println(CalcYellow, 1);
display.setCursor(0, (GrapWidth * 3) + 10);
display.println(CalcGreen, 1);
display.setCursor(0, (GrapWidth * 4) + 10);
display.println(CalcBlue, 1);
display.setCursor(0, (GrapWidth * 5) + 10);
display.println(CalcViolet, 1);
display.setCursor(0, 4);
dtostrf(CalcRed, 10, 1, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 1) + 5);
dtostrf(CalcOrange, 10, 1, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 2) + 5);
dtostrf(CalcYellow, 10, 1, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 3) + 5);
dtostrf(CalcGreen, 10, 1, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 4) + 5);
dtostrf(CalcBlue, 10, 1, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 5) + 5);
dtostrf(CalcViolet, 10, 1, FloatInChar);
display.println(FloatInChar);
}
display.setRotation(0);
if (menu_number == 2 || menu_number == 5) { //pokaż wartości bezpośrednie
//show raw values
if (menu_number == 2 || menu_number == 6) {
drawControls();
display.setRotation(0);
display.setCursor(0, 0);
display.setCursor(0, 25);
display.println("R");
display.setCursor((GrapWidth), 0);
display.setCursor((GrapWidth), 25);
display.println("O");
display.setCursor((GrapWidth) * 2, 0);
display.setCursor((GrapWidth) * 2, 25);
display.println("Y");
display.setCursor((GrapWidth) * 3, 0);
display.setCursor((GrapWidth) * 3, 25);
display.println("G");
display.setCursor((GrapWidth) * 4, 0);
display.setCursor((GrapWidth) * 4, 25);
display.println("B");
display.setCursor((GrapWidth) * 5, 0);
display.setCursor((GrapWidth) * 5, 25);
display.println("V");
display.setRotation(3);
display.setCursor(0, 5);
display.println(RawRed, 1);
display.setCursor(0, 4);
dtostrf(RawRed, 10, 0, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 1) + 5);
display.println(RawOrange, 1);
dtostrf(RawOrange, 10, 0, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 2) + 5);
display.println(RawYellow, 1);
dtostrf(RawYellow, 10, 0, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 3) + 5);
display.println(RawGreen, 1);
dtostrf(RawGreen, 10, 0, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 4) + 5);
display.println(RawBlue, 1);
dtostrf(RawBlue, 10, 0, FloatInChar);
display.println(FloatInChar);
display.setCursor(0, (GrapWidth * 5) + 5);
display.println(RawYellow, 1);
dtostrf(RawViolet, 10, 0, FloatInChar);
display.println(FloatInChar);
}
display.setRotation(0);
if (menu_number == 3 || menu_number == 6 ){ //pokaż grafy
//show relative calculated graph
if (menu_number == 3 || menu_number == 7 ){
maxValue = 0;
drawControls();
display.setRotation(0);
@@ -329,6 +330,84 @@ void loop() {
maxValue = 0.0;
}
//show raw data relative graph
if (menu_number == 4 || menu_number == 8 ){
maxValue = 0;
drawControls();
display.setRotation(0);
for (int i = 0; i < 5; i++) {
maxValue = max(maxValue, ReadValues[i]);
}
HeightRed = int((RawRed / maxValue) * GraphHeight);
HeightOrange = int((RawOrange / maxValue) * GraphHeight);
HeightYellow = int((RawYellow / maxValue) * GraphHeight);
HeightGreen = int((RawGreen / maxValue) * GraphHeight);
HeightBlue = int((RawBlue / maxValue) * GraphHeight);
HeightViolet = int((RawViolet / maxValue) * GraphHeight);
display.setCursor(1 * GrapWidth -10, 10);
if (HeightRed >25){
display.setTextColor(BLACK);
}
display.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, SSD1306_WHITE);
display.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, SSD1306_WHITE);
display.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, SSD1306_WHITE);
display.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, SSD1306_WHITE);
display.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, SSD1306_WHITE);
display.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, SSD1306_WHITE);
display.setCursor(1 * GrapWidth -10, 0);
if (HeightRed > 28){
display.setTextColor(BLACK);
}else {
display.setTextColor(WHITE);
}
display.println("R");
display.setCursor(2 * GrapWidth -10, 0);
if (HeightOrange > 28){
display.setTextColor(BLACK);
}else {
display.setTextColor(WHITE);
}
display.println("O");
display.setCursor(3 * GrapWidth -10, 0);
if (HeightYellow > 28){
display.setTextColor(BLACK);
}else {
display.setTextColor(WHITE);
}
display.println("Y");
display.setCursor(4 * GrapWidth -10, 0);
if (HeightGreen > 28){
display.setTextColor(BLACK);
}else {
display.setTextColor(WHITE);
}
display.println("G");
display.setCursor(5 * GrapWidth -10, 0);
if (HeightBlue > 28){
display.setTextColor(BLACK);
}else {
display.setTextColor(WHITE);
}
display.println("B");
display.setCursor(6 * GrapWidth -10, 0);
if (HeightViolet > 28){
display.setTextColor(BLACK);
}else {
display.setTextColor(WHITE);
}
display.println("V");
maxValue = 0.0;
}
display.display();
delay(500);
@@ -370,16 +449,3 @@ void drawControls() {
}
}
void printlnAlignedR(const float value, int x, int y, int prec) {
char textRepresentation;
int16_t x1, y1;
uint16_t w, h;
// textRepresentation = snprintf(buffer+j, 6, "%f\n", fp)
// round(value);
// display.getTextBounds(textRepresentation, x, y, &x1, &y1, &w, &h); //calc width of new string
display.setCursor(x - w / 2, y); //zmienić ten algorytm
// display.println(buf, 1);
display.println(textRepresentation);
}