I have double and 138x checked my brackets and they check out good.
So this has been going great, having so much fun learning from everyone in these forums.
My code is making each stair light up an adjacent HUE value which works great. It's setup to use motion sensors from the top and from the bottom of the stairs.
Problem is I cannot for the life of me (after researching for a few hours) figure out why my IF statement will not execute all of the code with its {}.
It executes the FOR loops perfectly, but disregards what is after the FOR loop still inside the IF statement.
I feel it is something stupid which is why I googled for a while before posting ![]()
It's not executing my commented parts "//XXXXXXXXXXXX"
#include "FastLED.h"
#define DATA_PIN 7
#define NUM_LEDS 120 //how many leds on the strip
#define ledgroup 10 //how many leds per stair
int brightness = 0;
CRGB leds[NUM_LEDS];
int alarmPinTop = 10; // PIR at the top of the stairs
int alarmPinBottom = 8; // PIR at the bottom of the stairs
int alarmValueTop = LOW; // Variable to hold the PIR status
int alarmValueBottom = LOW; // Variable to hold the PIR status
void setup()
{
//Serial.begin(9600);
// Serial.println("resetting");
//int ledgroup=2;
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
LEDS.setBrightness(155);
}
void loop()
{
alarmValueTop = digitalRead(alarmPinTop); // Constantly poll the PIR at the top of the stairs
//Serial.println(alarmPinTop);
alarmValueBottom = digitalRead(alarmPinBottom); // Constantly poll the PIR at the bottom of the stairs
//Serial.println(alarmPinBottom);
//Serial.println(alarmValueTop);
static int hue = 0;
if (alarmValueTop == HIGH)
{
for (int dot = 0 ; dot <= NUM_LEDS ; dot = (dot + ledgroup)) //this is how many steps in the staircase
{
hue = (25 / (NUM_LEDS / ledgroup)) * dot; //increase hue with each stair
for (int i = 0; i < ledgroup; i++) //this lights up each LED on that specific stair
{
//leds[dot-i] = CRGB::Red;
leds[dot + i] = CHSV(hue, 255, 255);
}
FastLED.show();
delay(500);
}
delay(1000); //XXXXXXXXXXXX
FastLED.clear(); //XXXXXXXXXXXX
FastLED.show(); //XXXXXXXXXXXX
delay(2000); //XXXXXXXXXXXX
}
if (alarmValueBottom == HIGH)
{
Serial.println("bottom pin detected");
for (int dot = NUM_LEDS ; dot >= 0 ; dot = (dot - ledgroup)) //this is how many steps in the staircase
{
hue = NUM_LEDS / ledgroup * dot / 10 * 1.75; //decrease hue with each stair
//Serial.println(hue);
for (int i = 0; i < ledgroup; i++) //this lights up each LED on that specific stair
{
//leds[dot-i] = CRGB::Red;
leds[dot - i] = CHSV(hue, 255, 255);
}
FastLED.show();
delay(500);
}
}
FastLED.clear(); //XXXXXXXXXXXX
FastLED.show(); //XXXXXXXXXXXX
}
Thank you so much for any help, I'm having so much fun ![]()