When I output values of the sharp sensor into the serial monitor the distance only reaches 13 cm even though the the range is supposed to be up to 80cm.
Any suggestions or ideas on why this may be would be greatly appreciated.
Thanks.
#include <Adafruit_NeoPixel.h>
#include <DistanceGP2Y0A21YK.h>
#define PIN 6
#define PIXEL 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRBW + NEO_KHZ800);
DistanceGP2Y0A21YK Dist;
int distance;
int R = 0;
int G = 0;
int B = 0;
void setup() {
strip.begin();
strip.show();
strip.setBrightness(64);
Serial.begin(9600);
Dist.begin(0);
}
void loop()
{
distance = Dist.getDistanceCentimeter();
Serial.print("\nDistance in centimers: ");
Serial.print(distance);
delay(10); //make it readable
if (distance > 9)
{
for (R && G && B; R < 150 && G < 150 && B < 150; R++ && G++ && B++) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(R, G, B));
strip.show();
delay(0);
}
delay(2);
}
// fade off
for (R && G && B; R > -1 && G > -1 && B > -1; R-- && G-- && B--) {
for (int j = 0; j < strip.numPixels(); j++) {
strip.setPixelColor(j, strip.Color(R, G, B));
strip.show();
delay(0);
}
delay(1);
}
}
else
{
for (int j = 0; j < 256; j++) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(255, 0, 0));
strip.show();
}
delay (1);
//blink off
for (int j = 64; j > 0; j--) {
for (int i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color(j, 0, 0));
strip.show();
}
delay (2);
}
}
}
}