I am trying to use a force sensor to change the color of a neopixel strip. I have three incremental force readings at which to change the color. When compiling the code I receive the error message, ("strip" was not declared in this scope) only for the last of the 3 iterations. Can anyone help explain what I need to do to fix this? Many thanks!!!!
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
void setup() {
// put your setup code here, to run once:
int Num_Pix=60; //60 pixels
int PINring=6; // assign strip to pin 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Num_Pix, PINring, NEO_GRB + NEO_KHZ800);
strip.begin();
strip.show();
uint32_t Blue=strip.Color(0,0,255); //set colors
uint32_t Red=strip.Color (255,0,0);
uint32_t Purple=strip.Color(127,0,127);
}
void loop() {
// put your main code here, to run repeatedly:
int Num_Pix=60;
int val;
int weightsensor=A1; //set force sensor to analog pin
val=analogRead (weightsensor); //set val to force sensor reading
if (val>600){ //if sensor reads over 600 turn strip red
for (int i=0; i<Num_Pix; i++)
strip.setPixelColor(i,Red);
strip.show();
delay (10);
else
if (val>300) { //if sensor reads over 300 turn strip purple
for (int i=0; i<Num_Pix; i++)
strip.setPixelColor(i,Purple);
strip.show();
delay (10);
}
else
if (val>100){ //if sensor reads over 100 turn strip blue
for (int i=0; i<Num_Pix; i++)
strip.setPixelColor(i,Blue);
strip.show();
delay (10);
}
}