Hello, I am relatively a newbie on programming and just started exploring neopixels recently.

Currently, I'm working on a project involving 2 neopixels strips and an IR obstacle sensor. The first strip changes effects when the IR sensor is triggered, the second strip should be running a different effect constantly but I cant get it to do so, so I just left it on fill_solid(). [PS. The code for the effects are mainly from Tweaking4All, thus the delays(). Also, I am not so sure how to make them into millis.]

Although It seems to be running fine on my Bluno Beetle but I just want to be sure since I might be missing some points. Thanks in advance!

/* This code uses 1 IR proximity sensor, 2 Neopixels strips that produces 2 different effects, and 1 5v LED strip that is constantly on and directly connected to the power supply. * The effects on Neopixel Strip A will change whenever the IR is triggered. Neopixel Strip B however is to produce the same effect throughout the program. * SOURCES: https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/ && IR Proximity Sensor interface code (Turns on an LED on when obstacle is detected, else off.) by blog.circuits4you.com 2016*/

Basically you want to see if it is time to update the pattern, if so go and make one step in the pattern and return.

This code shows how you can change the examples in the FastLED examples into a state machine. The pattern changes when a button is pressed. You want to change this button being pressed part of the code into looking at your IR sensor and deciding on what pattern you want.

// Multiple patterns in a state machine format// using the FastLED libiary// by Mike Cook 2017

#include "FastLED.h"

// first set up the parameters to use in the pattern callingunsigned long patternInterval [] = { 500, 40, 20, 200, 5 }; // how often each pattern updatesunsigned long lastUpdate [5] ; // for millis() when last update occurredboolean patternEnabled [] = {true,true,false,true,true}; // should the pattern be called at allbyte patternState[5]; // state machine variable for patterns - this initialises them to zero

// now set up the LEDs to use#define NUM_LEDS 64#define DATA_PIN 3#define CLOCK_PIN 13

void loop() { for(int i = 0; i<5; i++) { // go through all the patterns and see if it is time to call one if(patternEnabled[i] && millis() - lastUpdate[i] > patternInterval[i]){ lastUpdate[i] = millis(); callPatterns(i, patternState[i]); } }}

void callPatterns(int index, byte state) { (*patternPtrs[index])(index,state); //calls the pattern at the index of `index` in the array}

// These are the pattern functions written as a state machine// this is the Blink program in FastLED's example foldervoid blinkOne(int index,byte state) { if(state == 0){ leds[3] = CRGB::Blue; FastLED.show(); patternState[index] = 1; // move on the state machine for the next call } if(state == 1){ leds[3] = CRGB::Black; FastLED.show(); patternState[index] = 0; } }

// this is the Cylon program in FastLED's example folder// we will use LEDs 8 to 15 to show thisvoid cylon(int index,byte state) { static int i = 8; // replaces the loop index if(state == 0){ leds[i] = CRGB::Red; FastLED.show(); patternState[index] = 1; // move on the state machine for the next call } if(state == 1){ // now that we've shown the leds, reset the i'th led to black leds[i] = CRGB::Black; i++; // increment what was the loop variable if(i >= 16){ // we have finished one direction patternState[index] = 2; i--; } else { patternState[index] = 0; } } // Now go in the other direction only green if(state == 2){ leds[i] = CRGB::Green; FastLED.show(); patternState[index] = 3; // move on the state machine for the next call } if(state == 3){ // now that we've shown the leds, reset the i'th led to black leds[i] = CRGB::Black; i--; // decrement what was the loop variable if(i < 8){ // we have finished the return, go back to the start patternState[index] = 0; i= 8; // ready to start again } else { patternState[index] = 2; } // note that this could be better implemented but it has been written like this to keep it close to the origional example // so you can see what changes have been made }}