24RGB Neo_ring Control

Good Day All!
Please forgive me if I’m posting the code or link in a wrong way.
First time here, but been reading for a while.

This is my first Arduino Project!!
Some Guide is greatly appreciated, been for Hours trying different ways to make the code work but just don’t know how to tackle it.
I’m pretty good with tools and PC, learning to code with Arduino using tutorials from here and Youtube!

The code is attached.
Used the Adafruit_NeoPixel.h library
As you can see the Leds light up one by one till the 24th, then OFF in the same way when the IR switch don’t detect an object (IR output is a high signal) then it Loops all over again.
When an object is a detected (signal LOW) it clears all the Leds.
That Works!!!

I need help with the following:
would like have each led light up and as the IR detects an object the Leds freeze on that Position.
like a Button with leds on a game show!
lets say 6 leds lit up (1/4th of the ring) and the IR detected and object then it will no longer turn the others ON, but keep those 6 on for few milisecond or even flash as visual indication where it stopped.
then clear the Ring and loops again.
Also how to capture the time from the first led that turned on until object was detected and display it.

well this is what I have so Far!

Thank you in advance!!!

#include <Adafruit_NeoPixel.h>
#define button 2     //IR signal 
#define PIN 4        //WS2812 DI

boolean buttonState = 1;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_RGB + NEO_KHZ800);

  
  void setup() {
      strip.begin();
      strip.setBrightness(30); //adjust brightness here
      strip.show();           // Initialize all pixels to 'off'
      pinMode(button, INPUT);
   } 

  void loop() {

      buttonState = digitalRead(button);
      switch (buttonState) {
      case HIGH:
      colorWipe(strip.Color(0, 255, 0), 50); // Green
      colorWipe(strip.Color(0, 0, 0), 50); // Blank 
      break;
            
      case LOW:
      //colorWipe(strip.Color(255, 0, 000), 50); // RED
      //colorWipe(strip.Color(0, 0, 255), 50); // Blue
      colorWipe(strip.Color(0, 0, 0), 50); // Blank
      break;
      }
   }

//// LEDS EFFECTS///////////

void colorWipe(uint32_t c, uint8_t wait) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(42); 
  }
}

neopixel-24RGB-IR-SWITCH.ino (1.02 KB)

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :slight_smile:

Hi all again!
Anyone have any thoughts?
Can some one Guide me please...

Hi all Again!
Had some time to experiment!
here are the result:

like mentioned before, I wanted the led to freeze at the point where the IR switch detected an object. in this case pause .300 of a sec then clear.

here is the mods:

 void loop() {

      buttonState = digitalRead(button);
      switch (buttonState) {
      case HIGH:
      colorWipe(strip.Color(0, 255, 0), 50); // Green
      Clear_leds(strip.Color(0, 0, 0), 50); // Blank
      break;
            
      case LOW:
      Clear_leds(strip.Color(0, 0, 0), 50); // Blank
      break;
      }
   }

//// LEDS EFFECTS///////////

void colorWipe(uint32_t c, uint8_t wait) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
     if(digitalRead(button) == LOW){
     delay(300);
     Clear_leds(strip.Color(0, 0, 0), 50); // Blank
     break;
     }
    strip.setPixelColor(i, c);
    strip.show();
    delay(42); 
  }
}

void Clear_leds(uint32_t c, uint8_t wait) {
    for (uint16_t i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(5); 
  }
}

if there is another way to accomplish the same effect please guide me in that direction.

Also will work on how to get a TIME reading from where the first led turned ON to when it Stopped, then display that Reading. (I have no clue).
So far Few Sites point for External Hardware timer.

Pretty Sure we can use One of the Two the Uno has onboard. But Don’t know how… :confused: