Menu 2 3, info bar po lewej stronie
This commit is contained in:
@@ -21,7 +21,7 @@
|
|||||||
// obsługa przycisków zmieniających gain
|
// obsługa przycisków zmieniających gain
|
||||||
//obsługa włączania/wyłączania LED
|
//obsługa włączania/wyłączania LED
|
||||||
|
|
||||||
#define Version "1.0.0"
|
#define Version "1.0.1"
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
@@ -56,7 +56,7 @@ Adafruit_SSD1306 display(4);
|
|||||||
float gainValue = 64;
|
float gainValue = 64;
|
||||||
|
|
||||||
|
|
||||||
int menu_number = 0; // values:0 menu 1,2,3 bez led, 4,5,6 z LED
|
int menu_number = 3; // values:0 menu 1,2,3 bez led, 4,5,6 z LED
|
||||||
|
|
||||||
|
|
||||||
int LedPower = 0;
|
int LedPower = 0;
|
||||||
@@ -75,10 +75,9 @@ void setup() {
|
|||||||
display.setCursor(0, 10);
|
display.setCursor(0, 10);
|
||||||
display.println(Version);
|
display.println(Version);
|
||||||
display.display();
|
display.display();
|
||||||
delay(1500);
|
delay(500);
|
||||||
// Wire.begin();
|
Wire.begin();
|
||||||
// Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
sensor.begin();
|
sensor.begin();
|
||||||
pinMode(Btn1, INPUT_PULLUP);
|
pinMode(Btn1, INPUT_PULLUP);
|
||||||
@@ -89,14 +88,13 @@ void loop() {
|
|||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setTextColor(WHITE);
|
display.setTextColor(WHITE);
|
||||||
|
display.setRotation(0);
|
||||||
//rotation 0 default, pod wyswitlanie grafów
|
//rotation 0 default, pod wyswitlanie grafów
|
||||||
//roration 1 -tego nie, wyswietlacz pionowy w zla strone
|
//roration 1 -tego nie, wyswietlacz pionowy w zla strone
|
||||||
//roation 2 -tego nie do gory nogami
|
//roation 2 -tego nie do gory nogami
|
||||||
//rotation 3 pod wyswietlanie listy wartosci
|
//rotation 3 pod wyswietlanie listy wartosci
|
||||||
|
|
||||||
|
|
||||||
// data haverest
|
|
||||||
if (menu_number > 4 ) {
|
if (menu_number > 4 ) {
|
||||||
LedPower = 1;
|
LedPower = 1;
|
||||||
} else {
|
} else {
|
||||||
@@ -110,35 +108,8 @@ void loop() {
|
|||||||
sensor.disableBulb();
|
sensor.disableBulb();
|
||||||
sensor.takeMeasurements();
|
sensor.takeMeasurements();
|
||||||
}
|
}
|
||||||
|
sensor.takeMeasurements();
|
||||||
RawRed = sensor.getRed();
|
//gain change
|
||||||
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();
|
|
||||||
|
|
||||||
ReadValues[0] = CalcRed;
|
|
||||||
ReadValues[1] = CalcOrange;
|
|
||||||
ReadValues[2] = CalcYellow;
|
|
||||||
ReadValues[3] = CalcGreen;
|
|
||||||
ReadValues[4] = CalcBlue;
|
|
||||||
ReadValues[5] = CalcViolet;
|
|
||||||
//
|
|
||||||
////testowa linia
|
|
||||||
////void drawLine(64, 32, 1, 32, uint16_t color);
|
|
||||||
//
|
|
||||||
////linia 2 pix per 1 gin suma: 12 pix
|
|
||||||
////linia 3 linia 5pix dla led+kropka kolo niej 6 pix
|
|
||||||
//
|
|
||||||
|
|
||||||
if (digitalRead(Btn1) == 0) {
|
if (digitalRead(Btn1) == 0) {
|
||||||
if (gain < 3) {
|
if (gain < 3) {
|
||||||
gain = gain + 1;
|
gain = gain + 1;
|
||||||
@@ -160,8 +131,7 @@ if (gain == 0 ){
|
|||||||
gainValue = 64;
|
gainValue = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//gain change//menu change
|
||||||
|
|
||||||
if (digitalRead(Btn2) == 0) {
|
if (digitalRead(Btn2) == 0) {
|
||||||
if (menu_number < 8) {
|
if (menu_number < 8) {
|
||||||
menu_number = menu_number + 1;
|
menu_number = menu_number + 1;
|
||||||
@@ -170,12 +140,31 @@ if (digitalRead(Btn2) == 0){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//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();
|
||||||
|
|
||||||
|
ReadValues[0] = CalcRed;
|
||||||
|
ReadValues[1] = CalcOrange;
|
||||||
|
ReadValues[2] = CalcYellow;
|
||||||
|
ReadValues[3] = CalcGreen;
|
||||||
|
ReadValues[4] = CalcBlue;
|
||||||
|
ReadValues[5] = CalcViolet;
|
||||||
|
|
||||||
|
|
||||||
|
if (menu_number == 0 || menu_number != 1 || menu_number != 2 || menu_number != 3) {//pokaż menu konfiguracyjne
|
||||||
if (menu_number == 0 || menu_number != 1 ) {//pokaż menu konfiguracyjne
|
drawControls();
|
||||||
display.clearDisplay();
|
|
||||||
display.setRotation(0);
|
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println("GAIN");
|
display.println("GAIN");
|
||||||
display.setCursor(3, 8);
|
display.setCursor(3, 8);
|
||||||
@@ -205,9 +194,7 @@ if (digitalRead(Btn2) == 0){
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
if (menu_number == 1 || menu_number == 4 ) {//pokaż wartości przeliczone
|
if (menu_number == 1 || menu_number == 4 ) {//pokaż wartości przeliczone
|
||||||
|
drawControls();
|
||||||
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setRotation(0);
|
display.setRotation(0);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println("R");
|
display.println("R");
|
||||||
@@ -221,9 +208,6 @@ if (digitalRead(Btn2) == 0){
|
|||||||
display.println("B");
|
display.println("B");
|
||||||
display.setCursor((GrapWidth) * 5, 0);
|
display.setCursor((GrapWidth) * 5, 0);
|
||||||
display.println("V");
|
display.println("V");
|
||||||
|
|
||||||
|
|
||||||
//display.display();
|
|
||||||
display.setRotation(3);
|
display.setRotation(3);
|
||||||
display.setCursor(0, 10);
|
display.setCursor(0, 10);
|
||||||
display.println(CalcRed, 1);
|
display.println(CalcRed, 1);
|
||||||
@@ -237,119 +221,165 @@ if (digitalRead(Btn2) == 0){
|
|||||||
display.println(CalcBlue, 1);
|
display.println(CalcBlue, 1);
|
||||||
display.setCursor(0, (GrapWidth * 5) + 10);
|
display.setCursor(0, (GrapWidth * 5) + 10);
|
||||||
display.println(CalcViolet, 1);
|
display.println(CalcViolet, 1);
|
||||||
|
}
|
||||||
|
display.setRotation(0);
|
||||||
|
|
||||||
|
if (menu_number == 2 || menu_number == 5) { //pokaż wartości bezpośrednie
|
||||||
|
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.setRotation(3);
|
||||||
|
|
||||||
|
display.setCursor(0, 5);
|
||||||
|
display.println(RawRed, 1);
|
||||||
|
display.setCursor(0, (GrapWidth * 1) + 5);
|
||||||
|
display.println(RawOrange, 1);
|
||||||
|
display.setCursor(0, (GrapWidth * 2) + 5);
|
||||||
|
display.println(RawYellow, 1);
|
||||||
|
display.setCursor(0, (GrapWidth * 3) + 5);
|
||||||
|
display.println(RawGreen, 1);
|
||||||
|
display.setCursor(0, (GrapWidth * 4) + 5);
|
||||||
|
display.println(RawBlue, 1);
|
||||||
|
display.setCursor(0, (GrapWidth * 5) + 5);
|
||||||
|
display.println(RawYellow, 1);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
display.setRotation(0);
|
display.setRotation(0);
|
||||||
//
|
|
||||||
// if (menu_number == 2 || menu_number == 5) { //pokaż wartości bezpośrednie
|
if (menu_number == 3 || menu_number == 6 ){ //pokaż grafy
|
||||||
//// display.setRotation(2);
|
drawControls();
|
||||||
//
|
display.setRotation(0);
|
||||||
// display.setCursor(GrapWidth, 0);
|
|
||||||
// display.println("rR:");
|
for (int i = 0; i < 5; i++) {
|
||||||
// display.setCursor(GrapWidth, 10);
|
maxValue = max(maxValue, ReadValues[i]);
|
||||||
// display.println(RawRed, 1);
|
}
|
||||||
//
|
HeightRed = int((CalcRed / maxValue) * GraphHeight);
|
||||||
// display.setCursor(GrapWidth * 2, 0);
|
HeightOrange = int((CalcOrange / maxValue) * GraphHeight);
|
||||||
// display.println("rO:");
|
HeightYellow = int((CalcYellow / maxValue) * GraphHeight);
|
||||||
// display.setCursor(GrapWidth * 2, 10);
|
HeightGreen = int((CalcGreen / maxValue) * GraphHeight);
|
||||||
// display.println(RawOrange, 1);
|
HeightBlue = int((CalcBlue / maxValue) * GraphHeight);
|
||||||
//
|
HeightViolet = int((CalcViolet / maxValue) * GraphHeight);
|
||||||
// display.setCursor(GrapWidth * 3, 0);
|
|
||||||
// display.println("rY:");
|
|
||||||
// display.setCursor(GrapWidth * 3, 10);
|
display.setCursor(1 * GrapWidth -10, 10);
|
||||||
// display.println(RawYellow, 1);
|
if (HeightRed >25){
|
||||||
// display.setCursor(0, 20);
|
display.setTextColor(BLACK);
|
||||||
//
|
}
|
||||||
// display.setCursor(GrapWidth * 4, 0);
|
|
||||||
// display.println("rG:");
|
display.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, SSD1306_WHITE);
|
||||||
// display.setCursor(GrapWidth * 4, 10);
|
display.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, SSD1306_WHITE);
|
||||||
// display.println(RawGreen, 1);
|
display.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, SSD1306_WHITE);
|
||||||
//
|
display.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, SSD1306_WHITE);
|
||||||
// display.setCursor(GrapWidth * 5, 0);
|
display.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, SSD1306_WHITE);
|
||||||
// display.println("rB:");
|
display.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, SSD1306_WHITE);
|
||||||
// display.setCursor(GrapWidth * 5, 10);
|
display.setCursor(1 * GrapWidth -10, 0);
|
||||||
// display.println(RawBlue, 1);
|
if (HeightRed > 28){
|
||||||
//
|
display.setTextColor(BLACK);
|
||||||
// display.setCursor(GrapWidth * 6, 0);
|
}else {
|
||||||
// display.println("rV:");
|
display.setTextColor(WHITE);
|
||||||
// display.setCursor(GrapWidth * 6, 10);
|
}
|
||||||
// display.println(RawYellow, 1);
|
display.println("R:");
|
||||||
// }
|
display.setCursor(2 * GrapWidth -10, 0);
|
||||||
//// display.setRotation(0);
|
if (HeightOrange > 28){
|
||||||
//
|
display.setTextColor(BLACK);
|
||||||
// if (menu_number == 3 || menu_number == 6 ){ //pokaż grafy
|
}else {
|
||||||
//// display.setRotation(0);
|
display.setTextColor(WHITE);
|
||||||
//
|
}
|
||||||
// for (int i = 0; i < 5; i++) {
|
display.println("O:");
|
||||||
// maxValue = max(maxValue, ReadValues[i]);
|
display.setCursor(3 * GrapWidth -10, 0);
|
||||||
// }
|
if (HeightYellow > 28){
|
||||||
// HeightRed = int((CalcRed / maxValue) * GraphHeight);
|
display.setTextColor(BLACK);
|
||||||
// HeightOrange = int((CalcOrange / maxValue) * GraphHeight);
|
}else {
|
||||||
// HeightYellow = int((CalcYellow / maxValue) * GraphHeight);
|
display.setTextColor(WHITE);
|
||||||
// HeightGreen = int((CalcGreen / maxValue) * GraphHeight);
|
}
|
||||||
// HeightBlue = int((CalcBlue / maxValue) * GraphHeight);
|
display.println("Y:");
|
||||||
// HeightViolet = int((CalcViolet / maxValue) * GraphHeight);
|
display.setCursor(4 * GrapWidth -10, 0);
|
||||||
//
|
if (HeightGreen > 28){
|
||||||
//
|
display.setTextColor(BLACK);
|
||||||
// display.setCursor(1 * GrapWidth -10, 10);
|
}else {
|
||||||
// if (HeightRed >25){
|
display.setTextColor(WHITE);
|
||||||
// display.setTextColor(BLACK);
|
}
|
||||||
// }
|
display.println("G:");
|
||||||
//
|
display.setCursor(5 * GrapWidth -10, 0);
|
||||||
// display.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, SSD1306_WHITE);
|
if (HeightBlue > 28){
|
||||||
// display.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, SSD1306_WHITE);
|
display.setTextColor(BLACK);
|
||||||
// display.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, SSD1306_WHITE);
|
}else {
|
||||||
// display.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, SSD1306_WHITE);
|
display.setTextColor(WHITE);
|
||||||
// display.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, SSD1306_WHITE);
|
}
|
||||||
// display.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, SSD1306_WHITE);
|
display.println("B:");
|
||||||
// display.setCursor(1 * GrapWidth -10, 0);
|
display.setCursor(6 * GrapWidth -10, 0);
|
||||||
// if (HeightRed > 28){
|
if (HeightViolet > 28){
|
||||||
// display.setTextColor(BLACK);
|
display.setTextColor(BLACK);
|
||||||
// }else {
|
}else {
|
||||||
// display.setTextColor(WHITE);
|
display.setTextColor(WHITE);
|
||||||
// }
|
}
|
||||||
// display.println("R:");
|
display.println("V:");
|
||||||
// display.setCursor(2 * GrapWidth -10, 0);
|
|
||||||
// if (HeightOrange > 28){
|
maxValue = 0.0;
|
||||||
// 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();
|
display.display();
|
||||||
delay(50);
|
delay(500);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void drawControls() {
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setRotation(0);
|
||||||
|
// linia pozycyjna LED
|
||||||
|
display.drawPixel(127, 24, SSD1306_WHITE);
|
||||||
|
if (LedPower == 1) {
|
||||||
|
display.drawLine(127, 26, 127, 31, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
//gain:
|
||||||
|
display.drawPixel(127, 0, SSD1306_WHITE);
|
||||||
|
if (gain >= 1) {
|
||||||
|
display.drawPixel(127, 2, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
if (gain >= 2) {
|
||||||
|
display.drawPixel(127, 4, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
if (gain >= 3) {
|
||||||
|
display.drawPixel(127, 6, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
// menu
|
||||||
|
if (menu_number >= 1 ) {
|
||||||
|
display.drawPixel(127, 10, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
if ((menu_number >= 2 && menu_number <5 )|| menu_number >= 6 ) {
|
||||||
|
display.drawPixel(127, 12, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
if ((menu_number >= 3 && menu_number <5) || menu_number >= 7 ) {
|
||||||
|
display.drawPixel(127, 14, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
if ((menu_number >= 4 && menu_number <5 ) || menu_number >= 8 ) {
|
||||||
|
display.drawPixel(127, 16, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user