I'm very new to arduino but I'm making a project for my brother where I have an ultrasonic sound sensor trigger a series of RGB LED lights and it turns on fine, but will not turn off, can anybody tell me what modifications I need to make? Thank you
</
#include <FastLED.h>
#define microsecondsToInches
#define microsecondsToCentimeters
//Setup the variables for the HC-SR04
const int trigPin = 8;
const int echoPin = 9;
unsigned long time;
//Setup the variables for the NeoPixel Strip
// How many leds in your strip?
#define NUM_LEDS 39
// What pin is the NeoPixel's data line connected to?
#define DATA_PIN 6
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup(){
// initialize serial communication:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// put your setup code here, to run once:
FastLED.addLeds<WS2812, DATA_PIN>(leds, NUM_LEDS);
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds*.nscale8(250); } }*
void loop()
{
- long duration, distance;*
- digitalWrite(trigPin,HIGH);*
- delayMicroseconds(1000);*
- digitalWrite(trigPin, LOW);*
- duration=pulseIn(echoPin, HIGH);*
- distance =(duration/2)/29.1;*
- Serial.print(distance);*
- Serial.println("CM");*
- delay(10);*
if (distance <= 10) {
- for (int i = 0; i <= 39; i++) {*
_ leds = CRGB ( 0, 255, 0);_
* FastLED.show();*
* delay(20);*
* }*
* for (int i = 39; i >= 0; i--) {*
_ leds = CRGB ( 255, 0, 255);
* FastLED.show();
delay(20);
}*_
if (distance > 10) {
* for (int i = 0; i <= 0; i++) {*
_ leds = CRGB ( 0, 0, 0);
* FastLED.show();
delay(20); }}}}
/>
Basketball.ino (1.33 KB)*_