#include <NewPing.h>
#include <FastLED.h>
#define TRIGGER_PIN 4
#define ECHO_PIN 3
#define MAX_DISTANCE 379
#define NUM_LEDS 60
#define DATA_PIN 2
CRGB leds[NUM_LEDS]; // Define the array of leds
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
Serial.begin(115200);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
delay(50);
Serial.print("Ping: ");
Serial.print(sonar.ping_in());
Serial.println("in");
if (sonar.ping_in() <= 40) {
for(int dot = 0; dot < NUM_LEDS; dot++) {
leds[dot]= CRGB(20,0,25);
FastLED.show();
delay(10);
}
}
else if (sonar.ping_in() >= 41) {
fill_solid( &(leds[0]), NUM_LEDS, CRGB::Black);
FastLED.show();
}
}
I’m trying to insert a value range, so that an ultrasonic sensor responds if a value <=40, but >0 is detected. I think the solution is to insert a boolean operator like: (a>= 10 && a <=20)
However, I keep getting an error. I would appreciate any help/input. Thanks