Hello, first & foremost, apologies if I'm not using this forum correctly. I tried finding a 'user guide' for it before I went for it.
Now, my question;
I'm trying to make a WS2812 8 LED strip change colors with a pushbutton, (thats been achieved), WHILE it's on one particular color, I want it to flash another color IF it detects a vibration form a SW 420 sensor. I can make the sensor work by itself.. though trying to marry the codes together isn't working out.. I've tried a few different ways.. so far this seems to be the most logical, to me, though I cant get the vibe sensor to register a HIGH input while connected and coded with the rest of it.. What am I missing??.. here's what I've come up with so far...
#include <FastLED.h>
#define Button 2
int Count = 0;
#define NUM_LEDS 8
#define LED_PIN 3
CRGB leds[NUM_LEDS];
const int sensorPin = 9; // SW 420 Vibration sensor
int sensorState = 0;
int vibeState = (digitalRead(sensorPin));
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(5);
pinMode (Button, INPUT);
Serial.begin(9600);
pinMode(sensorPin,INPUT);
Serial.println(vibeState);
delay(500);
}
void loop() {
if(digitalRead(Button)==HIGH){
Count ++;
if(Count == 1 ){
fill_solid (leds, NUM_LEDS, CRGB::Green);
FastLED.show();
delay(250);
switch (vibeState)
{case 1:
for (int i = 0; i < 5; i++) {
fill_solid(leds,NUM_LEDS, CRGB::Orange);
FastLED.show();
delay(100);
fill_solid(leds, NUM_LEDS, CRGB::Black);
FastLED.show();
delay(100);
case 0:
break;
default:if(digitalRead(Button)==HIGH){
Count ++;
if(Count == 1 ){
fill_solid (leds, NUM_LEDS, CRGB::Green);
FastLED.show();
delay(250);}
}}}}
else if(Count == 2){
fill_solid (leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(250);}
else if (Count == 3){
fill_solid (leds,NUM_LEDS, CRGB::Blue);
FastLED.show();
delay(250);}
else if (Count == 4){
fill_solid (leds, NUM_LEDS, CRGB::White);
FastLED.show();
delay(250);}
else if (Count == 5){
fill_solid (leds, NUM_LEDS, CRGB::Black);
FastLED.show();
delay(250);}
}
}
Again, I would like to apologize for posting this incorrectly..