Problem incrementing an Array of Functions

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

Sometimes the 'state' of something is used. For example: Is the sun shining ?
Sometimes the 'event' is used. For example: Did someone open the door ?

Can you read this page: State Change Detection

if (i == 2);

Lose the ;

since i is constantly incremented while the door is closed (?), the scene shown when the door is opened is random?

Thank all of you. You got me back on track!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.