-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
323544e
commit 1de4a47
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*************************************************************************** | ||
This is a library for the APDS9960 digital proximity, ambient light, RGB, and gesture sensor | ||
This sketch puts the sensor in color mode and reads the RGB and clear values. | ||
Designed specifically to work with the Adafruit APDS9960 breakout | ||
----> http://www.adafruit.com/products/3595 | ||
These sensors use I2C to communicate. The device's I2C address is 0x39 | ||
Adafruit invests time and resources providing this open source code, | ||
please support Adafruit andopen-source hardware by purchasing products | ||
from Adafruit! | ||
Written by Dean Miller for Adafruit Industries. | ||
BSD license, all text above must be included in any redistribution | ||
***************************************************************************/ | ||
|
||
#include "Adafruit_APDS9960.h" | ||
#include <xCore.h> | ||
#include <xOD01.h> | ||
|
||
#if defined(ESP8266) | ||
#define RED RED | ||
#define GREEN GREEN | ||
#define BLUE BLUE | ||
#include <ESP8266WiFi.h> | ||
#define Serial Serial | ||
|
||
#elif defined(ARDUINO_SAMD_ZERO) | ||
#define RED CC03_RED | ||
#define GREEN CC03_GREEN | ||
#define BLUE CC03_BLUE | ||
#define Serial SerialUSB | ||
|
||
#elif defined(ARDUINO_AVR_PRO) | ||
#define RED CC01_RED | ||
#define GREEN CC01_GREEN | ||
#define BLUE CC01_BLUE | ||
#define Serial Serial | ||
|
||
#elif defined(ESP32) | ||
#define RED CW02_RED | ||
#define GREEN CW02_GREEN | ||
#define BLUE CW02_BLUE | ||
#define Serial Serial | ||
#endif | ||
|
||
Adafruit_APDS9960 apds; | ||
|
||
void setup() { | ||
|
||
#if defined(ESP8266) | ||
WiFi.forceSleepBegin(); | ||
Wire.begin(2, 14); | ||
Wire.setClockStretchLimit(15000); | ||
|
||
#elif defined(ARDUINO_SAMD_ZERO) | ||
Wire.begin(); | ||
|
||
#elif defined(ARDUINO_AVR_PRO) | ||
Wire.begin(); | ||
|
||
#elif defined(ESP32) | ||
Wire.begin(); | ||
|
||
#endif | ||
|
||
OLED.begin(); | ||
Serial.begin(115200); | ||
|
||
if(!apds.begin()){ | ||
OD01.println("failed to initialize device! Please check your wiring."); | ||
} | ||
else OD01.println("Device initialized!"); | ||
|
||
//enable color sensign mode | ||
apds.enableColor(true); | ||
} | ||
|
||
void loop() { | ||
//create some variables to store the color data in | ||
uint16_t r, g, b, c; | ||
|
||
//wait for color data to be ready | ||
while(!apds.colorDataReady()){ | ||
delay(5); | ||
} | ||
|
||
//get the data and print the different channels | ||
apds.getColorData(&r, &g, &b, &c); | ||
OD01.print("red: "); | ||
OD01.println(r); | ||
|
||
OD01.print(" green: "); | ||
OD01.println(g); | ||
|
||
OD01.print(" blue: "); | ||
OD01.println(b); | ||
|
||
OD01.print(" clear: "); | ||
OD01.println(c); | ||
OD01.println(); | ||
|
||
delay(500); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*************************************************************************** | ||
This is a library for the APDS9960 digital proximity, ambient light, RGB, and gesture sensor | ||
This sketch puts the sensor in color mode and reads the RGB and clear values. | ||
Designed specifically to work with the Adafruit APDS9960 breakout | ||
----> http://www.adafruit.com/products/3595 | ||
These sensors use I2C to communicate. The device's I2C address is 0x39 | ||
Adafruit invests time and resources providing this open source code, | ||
please support Adafruit andopen-source hardware by purchasing products | ||
from Adafruit! | ||
Written by Dean Miller for Adafruit Industries. | ||
BSD license, all text above must be included in any redistribution | ||
***************************************************************************/ | ||
|
||
#include "Adafruit_APDS9960.h" | ||
#include <xCore.h> | ||
#include <xOD01.h> | ||
|
||
Adafruit_APDS9960 apds; | ||
|
||
void setup() { | ||
|
||
Wire.begin(2, 14); | ||
OLED.begin(); | ||
Serial.begin(115200); | ||
|
||
if(!apds.begin()){ | ||
OD01.println("failed to initialize device! Please check your wiring."); | ||
} | ||
else OD01.println("Device initialized!"); | ||
|
||
//enable color sensign mode | ||
apds.enableColor(true); | ||
} | ||
|
||
void loop() { | ||
//create some variables to store the color data in | ||
uint16_t r, g, b, c; | ||
|
||
//wait for color data to be ready | ||
while(!apds.colorDataReady()){ | ||
delay(5); | ||
} | ||
|
||
//get the data and print the different channels | ||
apds.getColorData(&r, &g, &b, &c); | ||
OD01.print("red: "); | ||
OD01.println(r); | ||
|
||
OD01.print(" green: "); | ||
OD01.println(g); | ||
|
||
OD01.print(" blue: "); | ||
OD01.println(b); | ||
|
||
OD01.print(" clear: "); | ||
OD01.println(c); | ||
OD01.println(); | ||
|
||
delay(500); | ||
} |