Creating a fuel gauge using 16x NeoPixels

Hello people, I want to create a fuel gauge for my tractor using 2 x 8 Channel fully addressable WS2812B LED Strip


and a Fuel Sender Unit (basically a 190 ohms Variable Resistor)

I would like the NeoPixel LEDs to work in this sequence according to fuel level in the tank:
LED Sequence

I have found this code on the web for a similar project:

//picmicrolab.com
//https://www.picmicrolab.com/rgb-led-bar-graph/

//Improved RGB LED Bar Graph for Arduino platform based on // WS2812 chip - Data In
//with 16 active segments 
// strip.Color(0, 0, 0)); = Green
// strip.Color(255, 255, 0)); = Orange
// strip.Color(255, 0, 0)); = Red


#include <Adafruit_NeoPixel.h>

#define PIN A0 // // WS2812 chip - Data In
#define Pixel_Number 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixel_Number, PIN, NEO_GRB + NEO_KHZ800);

void setup() 
{
  pinMode(A1, INPUT);
  strip.begin();
  
}

void loop() 
{
 
 int analog_input = ( analogRead(A1) * 4.9 );
 delay(100);
if(analog_input  < 300 )
{
 strip.setPixelColor(0, strip.Color(0, 127, 0));
 for(int i=1;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
 strip.show();  
}
else if(analog_input  > 300 && analog_input  < 600 )
{
 strip.setPixelColor(0, strip.Color(0, 127, 0)); 
 strip.setPixelColor(1, strip.Color(0, 127, 0));
  for(int i=2;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
 strip.show(); 
}
else if(analog_input  > 600 && analog_input  < 900 )
{
 for(int i=0;i<2;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=3;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
 strip.show(); 
}
else if(analog_input  > 900 && analog_input  < 1200 )
{
  for(int i=0;i<3;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=4;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
 strip.show(); 
}
else if(analog_input  > 1200 && analog_input  < 1500 )
{
  for(int i=0;i<4;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=5;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 1500 && analog_input  < 1800 )
{
  for(int i=0;i<5;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=6;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 1800 && analog_input  < 2100 )
{
  for(int i=0;i<6;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=7;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 2100 && analog_input  < 2400 )
{
  for(int i=0;i<7;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=8;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 2400 && analog_input  < 2700 )
{
  for(int i=0;i<8;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=9;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 2700 && analog_input  < 3000 )
{
  for(int i=0;i<9;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=10;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 3000 && analog_input  < 3300 )
{
  for(int i=0;i<10;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));
 for(int i=11;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
    
 strip.show(); 
}
else if(analog_input  > 3300 && analog_input  < 3600 )
{
  for(int i=0;i<11;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));

 for(int i=12;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  strip.setPixelColor(10, strip.Color(255, 255, 0));   
 strip.show(); 
}
else if(analog_input  > 3600 && analog_input  < 3900 )
{
  for(int i=0;i<12;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));

 for(int i=13;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  strip.setPixelColor(10, strip.Color(255, 255, 0));  
  strip.setPixelColor(11, strip.Color(255, 255, 0));   
 strip.show(); 
}
else if(analog_input  > 3900 && analog_input  < 4200 )
{
  for(int i=0;i<13;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));

 for(int i=14;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  strip.setPixelColor(10, strip.Color(255, 255, 0));  
  strip.setPixelColor(11, strip.Color(255, 255, 0));   
  strip.setPixelColor(12, strip.Color(255, 255, 0)); 
 strip.show(); 
}
else if(analog_input  > 4200 && analog_input  < 4500 )
{
  for(int i=0;i<14;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));

 for(int i=15;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  strip.setPixelColor(10, strip.Color(255, 255, 0));  
  strip.setPixelColor(11, strip.Color(255, 255, 0));   
  strip.setPixelColor(12, strip.Color(255, 255, 0)); 
  strip.setPixelColor(13, strip.Color(255, 0, 0)); 
 strip.show(); 
}
else if(analog_input  > 4500 && analog_input  < 4800 )
{
  for(int i=0;i<15;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));

 for(int i=16;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  strip.setPixelColor(10, strip.Color(255, 255, 0));  
  strip.setPixelColor(11, strip.Color(255, 255, 0));   
  strip.setPixelColor(12, strip.Color(255, 255, 0)); 
  strip.setPixelColor(13, strip.Color(255, 0, 0)); 
  strip.setPixelColor(14, strip.Color(255, 0, 0)); 
 strip.show(); 
}
else if(analog_input  > 4800 )
{
  for(int i=0;i<16;i++)
    strip.setPixelColor(i, strip.Color(0, 127, 0));

 for(int i=16;i<Pixel_Number;i++)
    strip.setPixelColor(i, strip.Color(0, 0, 0));
  strip.setPixelColor(10, strip.Color(255, 255, 0));  
  strip.setPixelColor(11, strip.Color(255, 255, 0));   
  strip.setPixelColor(12, strip.Color(255, 255, 0)); 
  strip.setPixelColor(13, strip.Color(255, 0, 0)); 
  strip.setPixelColor(14, strip.Color(255, 0, 0)); 
  strip.setPixelColor(15, strip.Color(255, 0, 0)); 
 strip.show(); 
}
}

and have a created a wokwi project here : https://wokwi.com/projects/388458958731988993

This code is not doing exactly what I need, can anyone help me modify the code to achieve the LED sequence for the fuel gauge as on the picture above?

I am new to arduino.

Thanks

Interesting project, what type of tractor are we talking about. The electrical system can be very dirty and damage your Arduino. Here is some information that will help. If it is a toy forget the following.
There is a good app note AN2689 by ST on automotive electronics. reading it will help you a lot.
https://www.st.com/resource/en/application_note/cd00181783-protection-of-automotive-electronics-from-electrical-hazards-guidelines-for-design-and-component-selection-stmicroelectronics.pdf
Also take a look at this: Distilled Automotive Electronics Design | Analog Devices and then there is this one.
Transient Voltage Suppression in Automotive Applications

It's a John Deere 322 garden tractor that I use especially for snow removal.
I already use an aduino uno to control an intermittent wiper motor and have no issues.
I think I used a small DC to DC Buck converter to reduce the voltage to maybe 8 volts then use the VCC pin on the arduino.

The tractor is this one:

The fuel tank is plastic, therefor insulated from the tractor body ground.

Cheers

A collection of wokwi neopixel demos. Maybe there's something you can use as a starting point.

What wokwi search magic is this? I've tried the "+" (must include) and "-" (remove from search) and site:wokwi.com... and nothing for me... wow!kwi

This code sets the LED to the right color:


#include <Adafruit_NeoPixel.h>

#define PIN A0 // // WS2812 chip - Data In
#define Pixel_Number 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixel_Number, PIN, NEO_GRB + NEO_KHZ800);

void updateStrip(int ledsToLight, uint32_t colorOn, uint32_t colorOff){
  for(int x = 0; x < Pixel_Number; x++){
    if(x < ledsToLight) {
      strip.setPixelColor(x, colorOn);
    } else {
      strip.setPixelColor(x, colorOff);
    }
  }
  strip.show();
}

struct Level {
  int ledsToLight;
  uint32_t color;
};

#define max_colors 3
Level colors[max_colors] = {
  {3, strip.Color(255,0,0)},
  {5, strip.Color(255,128,0)},
  {16, strip.Color(0,255,0)},
};

uint32_t getColor(int ledsToLight){
  uint32_t ret = strip.Color(0,0,255);
  for(int x = 0; x < max_colors; x++){
    if (ledsToLight <= colors[x].ledsToLight){
      ret = colors[x].color;
      break;
    }
  }
  return ret;
}

void setup() 
{
  pinMode(A1, INPUT);
  strip.begin();
  
}

void loop() 
{
 auto colorOff = strip.Color(0,0,0);

 for(int x = 0; x <= Pixel_Number; x++){
  auto colorOn = getColor(x);
  updateStrip(x, colorOn, colorOff);
  delay(1000);
 }

}

Next steps would be to add analogRead() and calculate the number of LEDs that need to light up.

Thanks, how would I incorporated the following analogRead() "if" and "else if" conditions to your codes?

int analog_input = ( analogRead(A1) * 4.9 );
 delay(100);
if(analog_input  < 300 )

else if(analog_input  > 300 && analog_input  < 600 )
else if(analog_input  > 600 && analog_input  < 900 )
else if(analog_input  > 900 && analog_input  < 1200 )
else if(analog_input  > 1200 && analog_input  < 1500 )
else if(analog_input  > 1500 && analog_input  < 1800 )
else if(analog_input  > 1800 && analog_input  < 2100 )
else if(analog_input  > 2100 && analog_input  < 2400 )
else if(analog_input  > 2400 && analog_input  < 2700 )
else if(analog_input  > 2700 && analog_input  < 3000 )
else if(analog_input  > 3000 && analog_input  < 3300 )
else if(analog_input  > 3300 && analog_input  < 3600 )
else if(analog_input  > 3600 && analog_input  < 3900 )
else if(analog_input  > 3900 && analog_input  < 4200 )
else if(analog_input  > 4200 && analog_input  < 4500 )
else if(analog_input  > 4500 && analog_input  < 4800 )
else if(analog_input  > 4800 )

Almost there...

Please try to replace the loop():


void loop() 
{
  int ledsToLight = 0;

int analog_input = ( analogRead(A1) * 4.9 );
 delay(100);
if(analog_input  < 300 ) {ledsToLight = 0;}
else if(analog_input  > 300 && analog_input  < 600 ) {ledsToLight = 1;}
else if(analog_input  > 600 && analog_input  < 900 ) {ledsToLight = 2;}
else if(analog_input  > 900 && analog_input  < 1200 ) {ledsToLight = 3;}
else if(analog_input  > 1200 && analog_input  < 1500 ) {ledsToLight = 4;}
else if(analog_input  > 1500 && analog_input  < 1800 ) {ledsToLight = 5;}
else if(analog_input  > 1800 && analog_input  < 2100 ) {ledsToLight = 6;}
else if(analog_input  > 2100 && analog_input  < 2400 ) {ledsToLight = 7;}
else if(analog_input  > 2400 && analog_input  < 2700 ) {ledsToLight = 8;}
else if(analog_input  > 2700 && analog_input  < 3000 ) {ledsToLight = 9;}
else if(analog_input  > 3000 && analog_input  < 3300 ) {ledsToLight = 10;}
else if(analog_input  > 3300 && analog_input  < 3600 ) {ledsToLight = 11;}
else if(analog_input  > 3600 && analog_input  < 3900 ) {ledsToLight = 12;}
else if(analog_input  > 3900 && analog_input  < 4200 ) {ledsToLight = 13;}
else if(analog_input  > 4200 && analog_input  < 4500 ) {ledsToLight = 14;}
else if(analog_input  > 4500 && analog_input  < 4800 ) {ledsToLight = 15;}
else if(analog_input  > 4800 )  {ledsToLight = 16;}


 auto colorOff = strip.Color(0,0,0);
 auto colorOn = getColor(ledsToLight);
  updateStrip(ledsToLight, colorOn, colorOff);

}

Thanks
This seems to work just fine...
:grinning:

Ok how could I change this line:
if(analog_input < 300 ) {ledsToLight = 0;}
so it would flash all LEDs in Red, instead of no LEDs illuminated at all?

Thanks a lot for your help...

I still need to know that there are 0 ledsToLight. Therefore I would not change the calculation of it.

When I know its 0, I would not call updateStrip() anymore but rather doFlash()

Change

 auto colorOff = strip.Color(0,0,0);
 auto colorOn = getColor(ledsToLight);
  updateStrip(ledsToLight, colorOn, colorOff);

to

if (ledsToLight == 0) {
  doFlash();
} else {
 auto colorOff = strip.Color(0,0,0);
 auto colorOn = getColor(ledsToLight);
  updateStrip(ledsToLight, colorOn, colorOff);
}

doFlash() could be something like this:

void doFlash(){
  auto color = strip.Color(0,0,0);

  if((millis() / 540) & 1 != 0){
    color = strip.Color(255,0,0);
  }

  for (int x = 0; x < Pixel_Number; x++){
    strip.setPixelColor(x, color);
  }
  strip.show();
}

For wokwi.com...

sketch
#include <FastLED.h>

#define MAXPIX 16 // fuel gauge
#define PIXPIN 3 // data pin
#define MAXBRIGHT 255 // pixel brightness, 0 - 255 
#define SENSOR A0 // intput range 0vdc to 5vdc
CRGB gauge[MAXPIX]; // the neopixel string
int fuelLevel; // to know the level

void setup() {
  FastLED.addLeds<WS2812B, PIXPIN, GRB>(gauge, MAXPIX);
  FastLED.setBrightness(MAXBRIGHT); // Adjust the brightness value as needed
  FastLED.clear();
  FastLED.show();
}

void loop() {
  fuelLevel = map(analogRead(SENSOR), 0, 1023, 0, MAXPIX);
  FastLED.clear();

  if (!fuelLevel) // check for empty
    blink(); // blink the fuel gauge

  for (int i = 0; i < fuelLevel; i++) {
    if (i > 0 && i <= 3) // low
      gauge[i] = CRGB (255, 0, 0);
    if (i > 3 && i <= 6) // medium
      gauge[i] = CRGB (255, 255, 0);
    if (i > 6) // high
      gauge[i] = CRGB (0, 255, 0);
  }
  gauge[0] = CRGB(255, 0, 0); // "0" fuelLevel
  FastLED.show();
}

void blink() {
  FastLED.clear(); // remove old pixels
  FastLED.show(); // show buffer
  delay(100); // for flashing effect
  for (int j = 0; j < MAXPIX; j++) // use whole fuel gauge
    gauge[j] = CRGB (255, 0, 0); // color
  FastLED.show(); // show buffer
    delay(100);
}
diagram.json
{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    {
      "type": "wokwi-arduino-nano",
      "id": "nano",
      "top": 129.8,
      "left": -25.5,
      "rotate": 180,
      "attrs": {}
    },
    {
      "type": "wokwi-potentiometer",
      "id": "pot1",
      "top": 27.5,
      "left": 38.2,
      "attrs": { "value": "512" }
    },
    {
      "type": "wokwi-neopixel-matrix",
      "id": "ring1",
      "top": -2.8,
      "left": -251.08,
      "rotate": 270,
      "attrs": { "pixleate": "1", "rows": "1", "cols": "16" }
    }
  ],
  "connections": [
    [ "nano:GND.1", "pot1:GND", "black", [ "v-19.2", "h28.8" ] ],
    [ "nano:A0", "pot1:SIG", "green", [ "v-19.2", "h-9.2" ] ],
    [ "nano:5V", "pot1:VCC", "red", [ "v-9.6", "h29.6" ] ],
    [ "ring1:DIN", "nano:3", "green", [ "h9.6", "v205.4", "h76.8" ] ],
    [ "ring1:VCC", "nano:5V", "red", [ "h19.2", "v115.2", "h38.4" ] ],
    [ "nano:GND.1", "ring1:GND", "black", [ "v0" ] ]
  ],
  "dependencies": {}
}

I'm getting errors...
Where in the sketch do I put the lines starting with " void doFlash(){ " ?

Plug "wokwi neopixel" into your search engine.

:grinning:

Arduino is handling forward declarations for you. Place doFlash() after the last closing brace.

Usually, results are formatted by the search engine. Yours was the first I saw wokwi have results... and reading the URL, they were microPython.

Thanks, your coding is very clean, however, it is not doing exactly what I need, the last 5 LEDs switch from green, to orange or red depending on the fuel level. So when the gas thank is above 1/3 of the thank, all LED are green.

Cheers

Not sure what I am doing wrong, getting this errors:


Build failed!

sketch.ino: In function 'void loop()':
sketch.ino:75:3: error: 'doFlash' was not declared in this scope
doFlash();
^~~~~~~
sketch.ino:82:15: error: a function-definition is not allowed here before '{' token
void doFlash(){
^
sketch.ino:92:15: error: expected '}' at end of input
strip.show();
^

Error during build: exit status 1


Here is the complete sketch:

#include <Adafruit_NeoPixel.h>

#define PIN A0 // // WS2812 chip - Data In
#define Pixel_Number 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixel_Number, PIN, NEO_GRB + NEO_KHZ800);

void updateStrip(int ledsToLight, uint32_t colorOn, uint32_t colorOff){
  for(int x = 0; x < Pixel_Number; x++){
    if(x < ledsToLight) {
      strip.setPixelColor(x, colorOn);
    } else {
      strip.setPixelColor(x, colorOff);
    }
  }
  strip.show();
}

struct Level {
  int ledsToLight;
  uint32_t color;
};

#define max_colors 3
Level colors[max_colors] = {
  {3, strip.Color(255,0,0)},
  {5, strip.Color(255,128,0)},
  {16, strip.Color(0,255,0)},
};

uint32_t getColor(int ledsToLight){
  uint32_t ret = strip.Color(0,0,255);
  for(int x = 0; x < max_colors; x++){
    if (ledsToLight <= colors[x].ledsToLight){
      ret = colors[x].color;
      break;
    }
  }
  return ret;
}

void setup() 
{
  pinMode(A1, INPUT);
  strip.begin();
  
}

void loop() 
{
  int ledsToLight = 0;

int analog_input = ( analogRead(A1) * 4.9 );
 delay(100);
if(analog_input  < 300 ) {ledsToLight = 0;}
else if(analog_input  > 300 && analog_input  < 600 ) {ledsToLight = 1;}
else if(analog_input  > 600 && analog_input  < 900 ) {ledsToLight = 2;}
else if(analog_input  > 900 && analog_input  < 1200 ) {ledsToLight = 3;}
else if(analog_input  > 1200 && analog_input  < 1500 ) {ledsToLight = 4;}
else if(analog_input  > 1500 && analog_input  < 1800 ) {ledsToLight = 5;}
else if(analog_input  > 1800 && analog_input  < 2100 ) {ledsToLight = 6;}
else if(analog_input  > 2100 && analog_input  < 2400 ) {ledsToLight = 7;}
else if(analog_input  > 2400 && analog_input  < 2700 ) {ledsToLight = 8;}
else if(analog_input  > 2700 && analog_input  < 3000 ) {ledsToLight = 9;}
else if(analog_input  > 3000 && analog_input  < 3300 ) {ledsToLight = 10;}
else if(analog_input  > 3300 && analog_input  < 3600 ) {ledsToLight = 11;}
else if(analog_input  > 3600 && analog_input  < 3900 ) {ledsToLight = 12;}
else if(analog_input  > 3900 && analog_input  < 4200 ) {ledsToLight = 13;}
else if(analog_input  > 4200 && analog_input  < 4500 ) {ledsToLight = 14;}
else if(analog_input  > 4500 && analog_input  < 4800 ) {ledsToLight = 15;}
else if(analog_input  > 4800 )  {ledsToLight = 16;}



 if (ledsToLight == 0) {
  doFlash();
} else {
 auto colorOff = strip.Color(0,0,0);
 auto colorOn = getColor(ledsToLight);
  updateStrip(ledsToLight, colorOn, colorOff);
}

void doFlash(){
  auto color = strip.Color(0,0,0);

  if((millis() / 540) & 1 != 0){
    color = strip.Color(255,0,0);
  }

  for (int x = 0; x < Pixel_Number; x++){
    strip.setPixelColor(x, color);
  }
  strip.show();

It should look like this:


#include <Adafruit_NeoPixel.h>

#define PIN A0 // // WS2812 chip - Data In
#define Pixel_Number 16
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixel_Number, PIN, NEO_GRB + NEO_KHZ800);

void updateStrip(int ledsToLight, uint32_t colorOn, uint32_t colorOff){
  for(int x = 0; x < Pixel_Number; x++){
    if(x < ledsToLight) {
      strip.setPixelColor(x, colorOn);
    } else {
      strip.setPixelColor(x, colorOff);
    }
  }
  strip.show();
}

struct Level {
  int ledsToLight;
  uint32_t color;
};

#define max_colors 3
Level colors[max_colors] = {
  {3, strip.Color(255,0,0)},
  {5, strip.Color(255,128,0)},
  {16, strip.Color(0,255,0)},
};

uint32_t getColor(int ledsToLight){
  uint32_t ret = strip.Color(0,0,255);
  for(int x = 0; x < max_colors; x++){
    if (ledsToLight <= colors[x].ledsToLight){
      ret = colors[x].color;
      break;
    }
  }
  return ret;
}

void setup() 
{
  pinMode(A1, INPUT);
  strip.begin();
  
}

void loop() 
{
  int ledsToLight = 0;

int analog_input = ( analogRead(A1) * 4.9 );
 delay(100);
if(analog_input  < 300 ) {ledsToLight = 0;}
else if(analog_input  > 300 && analog_input  < 600 ) {ledsToLight = 1;}
else if(analog_input  > 600 && analog_input  < 900 ) {ledsToLight = 2;}
else if(analog_input  > 900 && analog_input  < 1200 ) {ledsToLight = 3;}
else if(analog_input  > 1200 && analog_input  < 1500 ) {ledsToLight = 4;}
else if(analog_input  > 1500 && analog_input  < 1800 ) {ledsToLight = 5;}
else if(analog_input  > 1800 && analog_input  < 2100 ) {ledsToLight = 6;}
else if(analog_input  > 2100 && analog_input  < 2400 ) {ledsToLight = 7;}
else if(analog_input  > 2400 && analog_input  < 2700 ) {ledsToLight = 8;}
else if(analog_input  > 2700 && analog_input  < 3000 ) {ledsToLight = 9;}
else if(analog_input  > 3000 && analog_input  < 3300 ) {ledsToLight = 10;}
else if(analog_input  > 3300 && analog_input  < 3600 ) {ledsToLight = 11;}
else if(analog_input  > 3600 && analog_input  < 3900 ) {ledsToLight = 12;}
else if(analog_input  > 3900 && analog_input  < 4200 ) {ledsToLight = 13;}
else if(analog_input  > 4200 && analog_input  < 4500 ) {ledsToLight = 14;}
else if(analog_input  > 4500 && analog_input  < 4800 ) {ledsToLight = 15;}
else if(analog_input  > 4800 )  {ledsToLight = 16;}


if (ledsToLight == 0) {
  doFlash();
} else {
 auto colorOff = strip.Color(0,0,0);
 auto colorOn = getColor(ledsToLight);
  updateStrip(ledsToLight, colorOn, colorOff);
}

}

void doFlash(){
  auto color = strip.Color(0,0,0);

  if((millis() / 540) & 1 != 0){
    color = strip.Color(255,0,0);
  }

  for (int x = 0; x < Pixel_Number; x++){
    strip.setPixelColor(x, color);
  }
  strip.show();
}

Thank you so much Rintin, this is exactly what I was looking for.
Cheers
:smiley: