diff --git a/LeonardoProMicro/SpectralSensor/SpectralSensor.ino b/LeonardoProMicro/SpectralSensor/SpectralSensor.ino
index 2ad398c..68f823b 100644
--- a/LeonardoProMicro/SpectralSensor/SpectralSensor.ino
+++ b/LeonardoProMicro/SpectralSensor/SpectralSensor.ino
@@ -1,29 +1,6 @@
/*
- This is a library written for the AS726X Spectral Sensor (Visible or IR) with I2C firmware
- specially loaded. SparkFun sells these at its website: www.sparkfun.com
-
- Written by Nathan Seidle & Andrew England @ SparkFun Electronics, July 12th, 2017
-
- https://github.com/sparkfun/Qwiic_Spectral_Sensor_AS726X
-
- Do you like this library? Help support SparkFun. Buy a board!
-
- Development environment specifics:
- Arduino IDE 1.8.1
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see .
-
-
---AVAILABLE FUNCTIONS---
AS726X(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);
- void takeMeasurements();
- void takeMeasurementsWithBulb();
void printMeasurements();
byte getTemperature();
float getTemperatureF();
@@ -32,8 +9,6 @@
void enableIndicator();
void disableIndicator();
void setIndicatorCurrent(byte current);
- void enableBulb();
- void disableBulb();
void setBulbCurrent(byte current);
void softReset();
void setGain(byte gain);
@@ -41,37 +16,12 @@
void enableInterrupt();
void disableInterrupt();
- //Get the various color readings
- int getViolet();
- int getBlue();
- int getGreen();
- int getYellow();
- int getOrange();
- int getRed();
-
- //Get the various NIR readings
- int getR();
- int getS();
- int getT();
- int getU();
- int getV();
- int getW();
-
- //Returns the various calibration data
- float getCalibratedViolet();
- float getCalibratedBlue();
- float getCalibratedGreen();
- float getCalibratedYellow();
- float getCalibratedOrange();
- float getCalibratedRed();
-
- float getCalibratedR();
- float getCalibratedS();
- float getCalibratedT();
- float getCalibratedU();
- float getCalibratedV();
- float getCalibratedW();
*/
+//2DO:
+// dodać literki pod grafami
+//obsługa przycisków zmieniających menu i LED
+// obsługa przycisków zmieniających gain
+
#include
#include
#include
@@ -80,6 +30,34 @@
AS726X sensor;
Adafruit_SSD1306 display(4);
+ int RawRed = 0;
+ int RawOrange = 0;
+ int RawYellow = 0;
+ int RawGreen = 0;
+ int RawBlue = 0;
+ int RawViolet = 0;
+ float CalcRed = 0.0;
+ float CalcOrange = 0.0;
+ float CalcYellow = 0.0;
+ float CalcGreen = 0.0;
+ float CalcBlue = 0.0;
+ float CalcViolet = 0.0;
+ int HeightRed = 0;
+ int HeightOrange = 0;
+ int HeightYellow = 0;
+ int HeightGreen = 0;
+ int HeightBlue = 0;
+ 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 LedPower = 0;
+ int GraphHeight = 64;
+// int GrapStart = ;
+ int GrapWidth = 20;
+ int ReadValues[6] = {0, 0, 0, 0, 0, 0};
+ int maxValue = 0;
+
void setup() {
Wire.begin();
@@ -93,37 +71,126 @@ void loop() {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
- sensor.takeMeasurements();
- //Prints all measurements
- //Visible readings
+ //data haverest
+ sensor.setGain(gain);
+ if (menu_number > 3 )
+
+ if (LedPower == 1) {
+ sensor.enableBulb();
+ sensor.takeMeasurementsWithBulb();
+ } else {
+ sensor.disableBulb();
+ sensor.takeMeasurements();
+ }
+
+ RawRed = sensor.getRed();
+ RawOrange = sensor.getOrange();
+ RawYellow = sensor.getYellow();
+ 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();
+ CalcOrange = sensor.getCalibratedOrange();
+ CalcYellow = sensor.getCalibratedYellow();
+ CalcGreen = sensor.getCalibratedGreen();
+ CalcBlue = sensor.getCalibratedBlue();
+ CalcViolet = sensor.getCalibratedViolet();
+
+ if (menu_number == 1 || menu_number == 4 ) {//pokaż wartości przeliczone
display.setCursor(0, 0);
display.println("R:");
display.setCursor(10, 0);
- display.println(sensor.getCalibratedRed(), 1);
+ display.println(CalcRed, 1);
display.setCursor(0, 10);
display.println("G:");
display.setCursor(10, 10);
- display.println(sensor.getCalibratedGreen(), 1);
+ display.println(CalcGreen, 1);
display.setCursor(0, 20);
display.println("B:");
display.setCursor(10, 20);
- display.println(sensor.getCalibratedBlue(), 1);
-
+ display.println(CalcBlue, 1);
display.setCursor(60, 0);
display.println("O:");
display.setCursor(70, 0);
- display.println(sensor.getCalibratedOrange(), 1);
+ display.println(CalcOrange, 1);
display.setCursor(60, 10);
display.println("Y:");
display.setCursor(70, 10);
- display.println(sensor.getCalibratedYellow(), 1);
+ display.println(CalcYellow, 1);
display.setCursor(60, 20);
display.println("V:");
display.setCursor(70, 20);
- display.println(sensor.getCalibratedViolet(), 1);
+ display.println(CalcViolet, 1);
+
+ }
+ if (menu_number == 2 || menu_number == 5) { //pokaż wartości bezpośrednie
+ display.setCursor(0, 0);
+ display.println("rR:");
+ display.setCursor(10, 0);
+ display.println(RawRed, 1);
+ display.setCursor(0, 10);
+ display.println("rG:");
+ display.setCursor(10, 10);
+ display.println(RawGreen, 1);
+ display.setCursor(0, 20);
+ display.println("rB:");
+ display.setCursor(10, 20);
+ display.println(RawBlue, 1);
+ display.setCursor(60, 0);
+ display.println("rO:");
+ display.setCursor(70, 0);
+ display.println(RawOrange, 1);
+ display.setCursor(60, 10);
+ display.println("rY:");
+ display.setCursor(70, 10);
+ display.println(RawYellow, 1);
+ display.setCursor(60, 20);
+ display.println("rV:");
+ display.setCursor(70, 20);
+ display.println(RawViolet, 1);
+ }
+ if (menu_number == 3 || menu_number == 6 ){ //pokaż grafy
+
+ 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;
+
+ 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.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.println("O:");
+ display.setCursor(0, 5 * GrapWidth -10);
+ display.println("Y:");
+ display.setCursor(0, 6 * GrapWidth -10);
+ display.println("V:");
+
+ }
+
display.display();
- delay(500);
-
-
+ delay(250);
}