Hi everyone, just as a disclaimer before I ask anything, this is my first real programming project so try not to judge me too harshly. I am working on a project to basically use a potentiometer to emulate a battery charge display. As the potentiometer gets turned, various segments of the Neopixel array will light up or turn off (think the battery indicator on your phone). As it is turned up, the array should "fill up" by lighting up pixels in order: from red, to yellow, to green. They should also speed up and slow down depending on how far the potentiometer is turned.
Currently, I can only get one pixel to light up and I cannot figure out why. Any help or pointers are greatly appreciate.
#include <Adafruit_NeoPixel.h>
//global definitions
#define PIN 6
#define LENGTH 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LENGTH, PIN, NEO_GRB + NEO_KHZ800);
int potValue = 0;
int rate = 0;
int i;
int blip = 10000; //ms
int n; //pixels
int blipTime = 0;
void setup() {
//Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
potValue =analogRead(A0);
//assign rates to pot values
if (potValue < 205 && potValue >= 0) {
rate = -200;
} else if (potValue < 410 && potValue >=206) {
rate = -100;
} else if (potValue < 615 && potValue >=411) {
rate = 2;
} else if (potValue < 820 && potValue >=616) {
rate = 100;
} else {
rate = 200;
}
////////////////
//light up LEDs
//first segment
if (rate == -200){
i = i + rate*(-1);
if (i >= blip) {
n = n + 1 ;
}
strip.setPixelColor(n, 255, 255, 255);
strip.show();
}
//second segment
else if (rate == -100){
i = i + rate*(-1);
if (i >= blip) {
n = n - 1 ;
}
strip.setPixelColor(n, 255, 255, 255);
strip.show();
}
//third segment
else if (rate == 0){
i = i + rate;
if (i >= blip) {
n = n - 1 ;
}
strip.setPixelColor(n, 255, 255, 255);
strip.show();
}
//fourth segment
else if (rate == 100){
i = i + rate;
if (i >= blip) {
n = n + 1 ;
}
strip.setPixelColor(n, 255, 255, 255);
strip.show();
}
//fifth segment
else if (rate == 200){
i = i + rate;
if (i >= blip) {
n = n + 1 ;
}
strip.setPixelColor(n, 255, 255, 255);
strip.show();
}
delay(500);
//Serial.println(rate);
}