@ScruffR Quick question about using the RGB + Map function.
The Gesture sensor at max brightness is giving these readings:
Iām trying to map this 0 -37889 to 0 - 255 by using this code:
void loop() {
RGB.control(true);
// Read the light levels (ambient, red, green, blue)
if ( !apds.readAmbientLight(ambient_light) ||
!apds.readRedLight(red_light) ||
!apds.readGreenLight(green_light) ||
!apds.readBlueLight(blue_light) ) {
Serial.println("Error reading light values");
} else {
Serial.print("Ambient: ");
Serial.print(ambient_light);
Serial.print(" Red: ");
Serial.print(red_light);
Serial.print(" Green: ");
Serial.print(green_light);
Serial.print(" Blue: ");
Serial.println(blue_light);
red = map(red_light, 0, 37889, 0, 255);
green = map(green_light, 0, 37889, 0, 255);
blue = map(blue_light, 0, 37889, 0, 255);
RGB.color(red, green, blue);
}
I had to add this code above the Void Loop to get it to compile:
uint16_t red = 0;
uint16_t green = 0;
uint16_t blue = 0;
Here is the whole .ino file.
#define DEBUG
// This #include statement was automatically added by the Particle IDE.
#include "SparkFun_APDS9960.h"
// Interrupt Pin
#define APDS9960_INT D3
// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
uint16_t ambient_light = 0;
uint16_t red_light = 0;
uint16_t green_light = 0;
uint16_t blue_light = 0;
uint16_t red = 0;
uint16_t green = 0;
uint16_t blue = 0;
void setup() {
// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("SparkFun APDS-9960 - ColorSensor"));
Serial.println(F("--------------------------------"));
// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}
// Start running the APDS-9960 light sensor (no interrupts)
if ( apds.enableLightSensor(false) ) {
Serial.println(F("Light sensor is now running"));
} else {
Serial.println(F("Something went wrong during light sensor init!"));
}
// Wait for initialization and calibration to finish
delay(500);
}
void loop() {
RGB.control(true);
// Read the light levels (ambient, red, green, blue)
if ( !apds.readAmbientLight(ambient_light) ||
!apds.readRedLight(red_light) ||
!apds.readGreenLight(green_light) ||
!apds.readBlueLight(blue_light) ) {
Serial.println("Error reading light values");
} else {
Serial.print("Ambient: ");
Serial.print(ambient_light);
Serial.print(" Red: ");
Serial.print(red_light);
Serial.print(" Green: ");
Serial.print(green_light);
Serial.print(" Blue: ");
Serial.println(blue_light);
red = map(red_light, 0, 37889, 0, 255);
green = map(green_light, 0, 37889, 0, 255);
blue = map(blue_light, 0, 37889, 0, 255);
RGB.color(red, green, blue);
}
// Wait 1 second before next reading
delay(1000);
}
The code runs and spits out the color readings over serial just fine but the RGB led just sits there OFF. So Iām pretty sure my mapping setup is not right as far as converting the larger 37,889 max reading down to the 8 bit 0-255 range.
Itās probably something simple but Iām short on time at the moment so I figured i would ask incase itās something that not so simple