Graf względny
This commit is contained in:
@@ -18,9 +18,9 @@
|
||||
|
||||
*/
|
||||
//2DO:
|
||||
// dodać literki pod grafami
|
||||
//obsługa przycisków zmieniających menu i LED
|
||||
// obsługa przycisków zmieniających menu i LED
|
||||
// obsługa przycisków zmieniających gain
|
||||
//obsługa włączania/wyłączania LED
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
@@ -50,13 +50,13 @@ Adafruit_SSD1306 display(4);
|
||||
int HeightViolet = 0;
|
||||
|
||||
byte gain = 3; // values: 0,1,2,3
|
||||
int menu_number = 1; // values: 1,2,3 bez led, 4,5,6 z LED
|
||||
int menu_number = 3; // values: 1,2,3 bez led, 4,5,6 z LED
|
||||
int LedPower = 0;
|
||||
int GraphHeight = 64;
|
||||
int GraphHeight = 32;
|
||||
// int GrapStart = ;
|
||||
int GrapWidth = 20;
|
||||
int ReadValues[6] = {0, 0, 0, 0, 0, 0};
|
||||
int maxValue = 0;
|
||||
float ReadValues[6] = {0, 0, 0, 0, 0, 0};
|
||||
float maxValue = 0.0;
|
||||
|
||||
|
||||
void setup() {
|
||||
@@ -73,7 +73,9 @@ void loop() {
|
||||
display.setTextColor(WHITE);
|
||||
//data haverest
|
||||
sensor.setGain(gain);
|
||||
if (menu_number > 3 )
|
||||
if (menu_number > 3 ){
|
||||
LedPower = 1;
|
||||
}
|
||||
|
||||
if (LedPower == 1) {
|
||||
sensor.enableBulb();
|
||||
@@ -83,27 +85,29 @@ void loop() {
|
||||
sensor.takeMeasurements();
|
||||
}
|
||||
|
||||
RawRed = sensor.getRed();
|
||||
RawRed = sensor.getRed();
|
||||
RawOrange = sensor.getOrange();
|
||||
RawYellow = sensor.getYellow();
|
||||
RawGreen = sensor.getGreen();
|
||||
RawBlue = sensor.getBlue();
|
||||
RawGreen = sensor.getGreen();
|
||||
RawBlue = sensor.getBlue();
|
||||
RawViolet = sensor.getViolet();
|
||||
ReadValues[0] = RawRed;
|
||||
ReadValues[1] = RawOrange;
|
||||
ReadValues[2] = RawYellow;
|
||||
ReadValues[3] = RawGreen;
|
||||
ReadValues[4] = RawBlue;
|
||||
ReadValues[5] = RawViolet;
|
||||
|
||||
|
||||
CalcRed = sensor.getCalibratedRed();
|
||||
|
||||
CalcRed = sensor.getCalibratedRed();
|
||||
CalcOrange = sensor.getCalibratedOrange();
|
||||
CalcYellow = sensor.getCalibratedYellow();
|
||||
CalcGreen = sensor.getCalibratedGreen();
|
||||
CalcBlue = sensor.getCalibratedBlue();
|
||||
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 == 1 || menu_number == 4 ) {//pokaż wartości przeliczone
|
||||
display.setCursor(0, 0);
|
||||
display.println("R:");
|
||||
@@ -163,34 +167,71 @@ void loop() {
|
||||
for (int i = 0; i < 5; i++) {
|
||||
maxValue = max(maxValue, ReadValues[i]);
|
||||
}
|
||||
HeightRed = (RawRed * maxValue) * GraphHeight;
|
||||
HeightOrange = (RawOrange * maxValue) * GraphHeight;
|
||||
HeightYellow = (RawYellow * maxValue) * GraphHeight;
|
||||
HeightGreen = (RawGreen * maxValue) * GraphHeight;
|
||||
HeightBlue = (RawBlue * maxValue) * GraphHeight;
|
||||
HeightViolet = (RawViolet * maxValue) * GraphHeight;
|
||||
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);
|
||||
|
||||
|
||||
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(0, 1 * GrapWidth -10);
|
||||
display.setCursor(1 * GrapWidth -10, 0);
|
||||
if (HeightRed >27){
|
||||
display.setTextColor(BLACK);
|
||||
}else {
|
||||
display.setTextColor(WHITE);
|
||||
}
|
||||
display.println("R:");
|
||||
display.setCursor(0, 2 * GrapWidth -10);
|
||||
display.println("G:");
|
||||
display.setCursor(0, 3 * GrapWidth -10);
|
||||
display.println("B:");
|
||||
display.setCursor(0, 4 * GrapWidth -10);
|
||||
display.setCursor(2 * GrapWidth -10, 0);
|
||||
if (HeightOrange >27){
|
||||
display.setTextColor(BLACK);
|
||||
}else {
|
||||
display.setTextColor(WHITE);
|
||||
}
|
||||
display.println("O:");
|
||||
display.setCursor(0, 5 * GrapWidth -10);
|
||||
display.setCursor(3 * GrapWidth -10, 0);
|
||||
if (HeightYellow >27){
|
||||
display.setTextColor(BLACK);
|
||||
}else {
|
||||
display.setTextColor(WHITE);
|
||||
}
|
||||
display.println("Y:");
|
||||
display.setCursor(0, 6 * GrapWidth -10);
|
||||
display.setCursor(4 * GrapWidth -10, 0);
|
||||
if (HeightGreen >27){
|
||||
display.setTextColor(BLACK);
|
||||
}else {
|
||||
display.setTextColor(WHITE);
|
||||
}
|
||||
display.println("G:");
|
||||
display.setCursor(5 * GrapWidth -10, 0);
|
||||
if (HeightBlue >27){
|
||||
display.setTextColor(BLACK);
|
||||
}else {
|
||||
display.setTextColor(WHITE);
|
||||
}
|
||||
display.println("B:");
|
||||
display.setCursor(6 * GrapWidth -10, 0);
|
||||
if (HeightViolet >27){
|
||||
display.setTextColor(BLACK);
|
||||
}else {
|
||||
display.setTextColor(WHITE);
|
||||
}
|
||||
display.println("V:");
|
||||
|
||||
maxValue = 0.0;
|
||||
}
|
||||
|
||||
display.display();
|
||||
delay(250);
|
||||
delay(750);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user