|
| 1 | +/* |
| 2 | + * Simple Arduino spectrometer. |
| 3 | + */ |
| 4 | + |
| 5 | +#include "Adafruit_AS726x.h" |
| 6 | + |
| 7 | +//create the object |
| 8 | +Adafruit_AS726x ams; |
| 9 | + |
| 10 | +//buffer to hold raw values |
| 11 | +//uint16_t sensorValues[AS726x_NUM_CHANNELS]; |
| 12 | + |
| 13 | +//buffer to hold calibrated values (not used by default in this example) |
| 14 | +float calibratedValues[AS726x_NUM_CHANNELS]; |
| 15 | + |
| 16 | +void setup() |
| 17 | +{ |
| 18 | + Serial.begin(57600); //start fast Serial |
| 19 | + |
| 20 | + // initialize digital pin LED_BUILTIN as an output. |
| 21 | + pinMode(LED_BUILTIN, OUTPUT); |
| 22 | + |
| 23 | + //begin and make sure we can talk to the sensor |
| 24 | + if(!ams.begin()){ |
| 25 | + Serial.println("Error, no sensor!"); |
| 26 | + while(1); |
| 27 | + } |
| 28 | + |
| 29 | + ams.setIndicateCurrent(LIMIT_1MA); //set current for indicator LED 1mA |
| 30 | + ams.indicateLED(false); //turn on indicator LED |
| 31 | + |
| 32 | + ams.setDrvCurrent(LIMIT_12MA5); //LIMIT_12MA5, LIMIT_25MA, LIMIT_50MA, or LIMIT_100MA |
| 33 | + |
| 34 | + ams.drvOff(); //turn off drive LED |
| 35 | + //ams.drvOn(); |
| 36 | + |
| 37 | + ams.setConversionType(MODE_2); //MODE_0, MODE_1, MODE_2, ONE_SHOT |
| 38 | + ams.setGain(GAIN_64X); //GAIN_1X, GAIN_3X7, GAIN_16X, or GAIN_64X |
| 39 | + ams.setIntegrationTime(50); //actual integration time will be time*2.8ms |
| 40 | + |
| 41 | +} |
| 42 | + |
| 43 | +void loop() |
| 44 | +{ |
| 45 | + //read the device temperature |
| 46 | + uint8_t temp = ams.readTemperature(); |
| 47 | + |
| 48 | + ams.startMeasurement(); //begin a measurement |
| 49 | + |
| 50 | + //wait till data is available |
| 51 | + bool ready = false; |
| 52 | + while(!ready) |
| 53 | + { |
| 54 | + delay(5); |
| 55 | + ready = ams.dataReady(); |
| 56 | + } |
| 57 | + |
| 58 | + //read the values! |
| 59 | + //ams.readRawValues(sensorValues); |
| 60 | + ams.readCalibratedValues(calibratedValues); |
| 61 | + |
| 62 | + /* |
| 63 | + Serial.print("Temp: "); Serial.print(temp); |
| 64 | + Serial.print(" Violet: "); Serial.print(sensorValues[AS726x_VIOLET]); |
| 65 | + Serial.print(" Blue: "); Serial.print(sensorValues[AS726x_BLUE]); |
| 66 | + Serial.print(" Green: "); Serial.print(sensorValues[AS726x_GREEN]); |
| 67 | + Serial.print(" Yellow: "); Serial.print(sensorValues[AS726x_YELLOW]); |
| 68 | + Serial.print(" Orange: "); Serial.print(sensorValues[AS726x_ORANGE]); |
| 69 | + Serial.print(" Red: "); Serial.print(sensorValues[AS726x_RED]); |
| 70 | +
|
| 71 | + Serial.println(); |
| 72 | + Serial.println(); |
| 73 | + */ |
| 74 | + |
| 75 | + // VBGYOR |
| 76 | + //Serial.print("TEMP: "); Serial.print(temp); |
| 77 | + //Serial.print(" | V: "); |
| 78 | + Serial.print(calibratedValues[AS726x_VIOLET]); Serial.print(", "); |
| 79 | + //Serial.print(" | B: "); |
| 80 | + Serial.print(calibratedValues[AS726x_BLUE]); Serial.print(", "); |
| 81 | + //Serial.print(" | G: "); |
| 82 | + Serial.print(calibratedValues[AS726x_GREEN]); Serial.print(", "); |
| 83 | + //Serial.print(" | Y: "); |
| 84 | + Serial.print(calibratedValues[AS726x_YELLOW]); Serial.print(", "); |
| 85 | + //Serial.print(" | O: "); |
| 86 | + Serial.print(calibratedValues[AS726x_ORANGE]); Serial.print(", "); |
| 87 | + //Serial.print(" | R: "); |
| 88 | + Serial.print(calibratedValues[AS726x_RED]); |
| 89 | + |
| 90 | + //Serial.println(); |
| 91 | + Serial.println(); |
| 92 | + //Serial.println(); |
| 93 | + //Serial.println(); |
| 94 | + |
| 95 | + delay(5000); |
| 96 | +} |
0 commit comments