Hello, I'm using a range finder and would like to control different light colours at a set distance. but when i try to mix the colours ie to get an orange .. it still come up as red. can some help.
/*
*/
#include <Wire.h>
#include <LIDARLite.h>
LIDARLite myLidarLite;
int greenPin = 12;
int bluePin = 11;
int redPin = 13;
int Brightness = 255;
void setup() {
Serial.begin(115200); // Initialize serial connection to display distance readings
myLidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz
myLidarLite.configure(0); // Change this number to try out alternate configurations
// rgb
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(redPin, OUTPUT);
}
void loop() {
if (myLidarLite.distance() < 80 && myLidarLite.distance() > 45)
{
Serial.println("GREEN LIGHT");
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
analogWrite(greenPin, 255);
}
else if (myLidarLite.distance() < 40 && myLidarLite.distance() >25)
{
Serial.println(" ORANGE LIGHT ");
analogWrite(redPin, 200);
analogWrite(bluePin, 0);
analogWrite(greenPin, 20);
}
else if (myLidarLite.distance() < 20)
{
Serial.println(" RED LIGHT ");
analogWrite(redPin, 255);
analogWrite(bluePin, 0);
analogWrite(greenPin, 0);
}
else
{
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
analogWrite(greenPin, 0);
}
}