This is my first program and first post so please keep it supper simple. I am attempting to turn on LEDs and increment though an array of functions (LED scenes) each time a Hall Effect Switch sees the absence of a magnet (a door is opened), and turn off the lights when it sees the magnet. I only have 2 scenes in this example which works (turns on and off) but won’t increment to the next scene. I thought something was wrong with how i’m incrementing but i’ve tried a bunch of options. Please help.
[code]
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 3
#define DATA_PIN 3
#define CLOCK_PIN 2
#define BACK_LIGHT 0
#define CABIN_LIGHT 1
#define SHELF_LIGHT 2
const int hallPin = 7;
int hallState = 0;
int lastHallState = 0;
// Define the array of leds
CRGB leds[NUM_LEDS];
// Define Functions named Scene
void Scene0()
{
leds[BACK_LIGHT] = CRGB::Green;
FastLED.show();
leds[CABIN_LIGHT] = CRGB::Red;
FastLED.show();
leds[SHELF_LIGHT] = CRGB::Blue;
FastLED.show();
}
void Scene1()
{
leds[BACK_LIGHT] = CRGB::Red;
FastLED.show();
leds[CABIN_LIGHT] = CRGB::Red;
FastLED.show();
leds[SHELF_LIGHT] = CRGB::Red;
FastLED.show();
}
typedef void (*GeneralFunction) ();
// Define the array of Scene pointers
GeneralFunction SceneArray [] =
{
Scene0,
Scene1,
};
void setup()
{
FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
pinMode(hallPin, INPUT);
}
void loop()
{
// Check the State of the Hall Effect
hallState = digitalRead(hallPin);
int static i = 0;
if (hallState == HIGH)
{
SceneArray [i] ();
}
else
// Keep the LEDs off
{
leds[BACK_LIGHT] = CRGB::Black;
FastLED.show();
leds[CABIN_LIGHT] = CRGB::Black;
FastLED.show();
leds[SHELF_LIGHT] = CRGB::Black;
FastLED.show();
i ++;
if (i == 2);
{
i = 0;
}
}
}
[/code]Preformatted text