SpectralSensor Spectral Sensor Spektroskop + test wyświetlacza
This commit is contained in:
129
LeonardoProMicro/SpectralSensor/SpectralSensor.ino
Normal file
129
LeonardoProMicro/SpectralSensor/SpectralSensor.ino
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
---AVAILABLE FUNCTIONS---
|
||||
AS726X(TwoWire &wirePort = Wire, byte gain = 3, byte measurementMode = 3);
|
||||
void takeMeasurements();
|
||||
void takeMeasurementsWithBulb();
|
||||
void printMeasurements();
|
||||
byte getTemperature();
|
||||
float getTemperatureF();
|
||||
void setMeasurementMode(byte mode);
|
||||
boolean dataAvailable();
|
||||
void enableIndicator();
|
||||
void disableIndicator();
|
||||
void setIndicatorCurrent(byte current);
|
||||
void enableBulb();
|
||||
void disableBulb();
|
||||
void setBulbCurrent(byte current);
|
||||
void softReset();
|
||||
void setGain(byte gain);
|
||||
void setIntegrationTime(byte integrationValue);
|
||||
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();
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "AS726X.h"
|
||||
|
||||
AS726X sensor;
|
||||
Adafruit_SSD1306 display(4);
|
||||
|
||||
void setup() {
|
||||
Wire.begin();
|
||||
Serial.begin(115200);
|
||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
||||
display.clearDisplay();
|
||||
sensor.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
display.clearDisplay();
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(WHITE);
|
||||
sensor.takeMeasurements();
|
||||
//Prints all measurements
|
||||
//Visible readings
|
||||
display.setCursor(0, 0);
|
||||
display.println("R:");
|
||||
display.setCursor(10, 0);
|
||||
display.println(sensor.getCalibratedRed(), 1);
|
||||
display.setCursor(0, 10);
|
||||
display.println("G:");
|
||||
display.setCursor(10, 10);
|
||||
display.println(sensor.getCalibratedGreen(), 1);
|
||||
display.setCursor(0, 20);
|
||||
display.println("B:");
|
||||
display.setCursor(10, 20);
|
||||
display.println(sensor.getCalibratedBlue(), 1);
|
||||
|
||||
display.setCursor(60, 0);
|
||||
display.println("O:");
|
||||
display.setCursor(70, 0);
|
||||
display.println(sensor.getCalibratedOrange(), 1);
|
||||
display.setCursor(60, 10);
|
||||
display.println("Y:");
|
||||
display.setCursor(70, 10);
|
||||
display.println(sensor.getCalibratedYellow(), 1);
|
||||
display.setCursor(60, 20);
|
||||
display.println("V:");
|
||||
display.setCursor(70, 20);
|
||||
display.println(sensor.getCalibratedViolet(), 1);
|
||||
|
||||
display.display();
|
||||
delay(500);
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user