Problems with libraries using Finite State Machine

I am trying the develop a system for irrigating the garden and it has been suggested that I use FSM.

I had a lot of difficulty at first as although I installed the libraries required it still required another library, namely Wprogram.h.
I enventually found that you can use Arduino.h instead and the example program ran OK.

I then proceded to modify a copy of a program that I am working on, to see if I could make it work any better using FSM.

As I only wanted to turn a relay on and off I removed the fade in and fade out code.

I added these lines :

#include <FiniteStateMachine.h>
 //initialize states0
State On = State(ledOn);
State Off = State(ledOff); 
void ledOn(){led.on();}
void ledOff(){led.off();}
FSM relayStateMachine = FSM(On);     //initialize state machine, start in state: On

//In the if that checks the Alarm state:

ledStateMachine.transitionTo(On);

//And another if to switch the relay off:
if(millis() > EndTime)
{
  ledStateMachine.transitionTo(Off);
 DS3231_clear_a1f();
    }

When I try to compile I get the following errors:

rtc_ds3231_alarm12.ino.ino: In function ‘void ledOn()’:
rtc_ds3231_alarm12.ino.ino:67:14: error: ‘led’ was not declared in this scope
rtc_ds3231_alarm12.ino.ino: In function ‘void ledOff()’:
rtc_ds3231_alarm12.ino.ino:68:15: error: ‘led’ was not declared in this scope
rtc_ds3231_alarm12.ino.ino: In function ‘void loop()’:
rtc_ds3231_alarm12.ino.ino:116:1: error: ‘ledStateMachine’ was not declared in this scope
rtc_ds3231_alarm12.ino.ino:123:3: error: ‘ledStateMachine’ was not declared in this scope
‘led’ was not declared in this scope

I had assumed that you would need the led.h, so I included that at the beginning.
I also tried to add int led, but that gave the following errors:

rtc_ds3231_alarm12.ino.ino: In function ‘void ledOn()’:
rtc_ds3231_alarm12.ino.ino:67:18: error: request for member ‘on’ in ‘led’, which is of non-class type ‘int’
rtc_ds3231_alarm12.ino.ino: In function ‘void ledOff()’:
rtc_ds3231_alarm12.ino.ino:68:19: error: request for member ‘off’ in ‘led’, which is of non-class type ‘int’

Why does it not work, as the same lines were in the example?
Is there a library that I am not including?
Can’t even test if the code is working for the program, until I sort out these issues.

Please help!

Copy of the code as it stands at the moment:

// rtc_ds3231_alarm7 (Working with sensor)
// during an alarm the INT pin of the RTC is pulled low
//SDA - pin A4
// SCL - pin A5
// this is handy for minimizing power consumption for sensor-like devices,
// since they can be started up by this pin on given time intervals.
#include <FiniteStateMachine.h>
#include <Wire.h>
#include "ds3231.h"
#include <led.h>
#define BUFF_MAX 256
// time when to wake up
uint8_t wake1_HOUR = 17;
uint8_t wake1_MINUTE = 00;
uint8_t wake1_SECOND = 00;

uint8_t wake2_HOUR = 17;
uint8_t wake2_MINUTE = 59;
int relaypin = 10;
int SQWpin = 8;
int tankSensePin = A0;
int curCounter = 0;
int sensorValue = 0;
boolean Alarm1On = false;
boolean Alarm2On = false;
unsigned long StartTime=0;
unsigned long EndTime=0;
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
// constants won't change :
unsigned long prev = 1000, interval = 1000;
void set_alarm(void) {
  // flags define what calendar component to be checked against the current time in order
  // to trigger the alarm - see datasheet
  // A1M1 (seconds) (0 to enable, 1 to disable)
  // A1M2 (minutes) (0 to enable, 1 to disable)
  // A1M3 (hour)    (0 to enable, 1 to disable)
  // A1M4 (day)     (0 to enable, 1 to disable)
  // DY/DT          (dayofweek == 1/dayofmonth == 0)
  uint8_t flags1[5] = { 0, 0, 0, 1, 1 };

  // A2M2 (minutes) (0 to enable, 1 to disable)
  // A2M3 (hour)    (0 to enable, 1 to disable)
  // A2M4 (day)     (0 to enable, 1 to disable)
  uint8_t flags2[3] = {0, 0, 1};

  // set Alarm1
  DS3231_set_a1(wake1_SECOND, wake1_MINUTE, wake1_HOUR, 0, flags1);

  // activate Alarm1
  DS3231_set_creg(DS3231_INTCN | DS3231_A1IE);

  // set Alarm2
  DS3231_set_a2(wake2_MINUTE, wake2_HOUR, 0, flags2);

  // activate Alarm2
  DS3231_set_creg(DS3231_INTCN | DS3231_A2IE);

}
const byte NUMBER_OF_STATES = 2; //how many states are we cycling through?
int led;
 //initialize states0
State On = State(ledOn);
State Off = State(ledOff); 
void ledOn(){led.on();}
void ledOff(){led.off();}
FSM relayStateMachine = FSM(On);     //initialize state machine, start in state: On
void setup() {
  Serial.begin(9600);
  Wire.begin();
  pinMode(SQWpin, INPUT);
  pinMode(relaypin, OUTPUT);
  pinMode(tankSensePin, INPUT);
  DS3231_init(DS3231_INTCN);
  DS3231_clear_a1f();
  DS3231_clear_a2f();
  set_alarm();
}

void loop()
{

if(DS3231_triggered_a1()== true){    
   StartTime=millis();
   EndTime=StartTime+60000;
   Serial.println(StartTime);
   Serial.println(EndTime); 
} 
//boolean myAlarm1On = false ;
//boolean myAlarm2On = false ;  
  char buff[BUFF_MAX];
  unsigned long now = millis();

   boolean Alarm2On = false;
  struct ts t;

  // once a while show what is going on
  if ((now - prev > interval) && (Serial.available() <= 0)) {
    DS3231_get(&t);
    // display current time
    snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year,
             t.mon, t.mday, t.hour, t.min, t.sec);
             Serial.println(buff);   
//boolean Alarm1On = DS3231_triggered_a1();
boolean Alarm2On = DS3231_triggered_a2();

    int tankSenseReading = analogRead(tankSensePin);
    Serial.println(tankSenseReading);
   
    if (tankSenseReading>500 && millis() > StartTime && millis() < EndTime) {
      // INT/SQW has been pulled low
      Serial.println(" -> alarm1 has been triggered");
//      digitalWrite(relaypin, HIGH);
ledStateMachine.transitionTo(On);

       Serial.println(StartTime);
       Serial.println(EndTime);
  }       
if(millis() > EndTime)
{
  ledStateMachine.transitionTo(Off);
 DS3231_clear_a1f();
    }
prev = now;
}
}

I had assumed that you would need the led.h, so I included that at the beginning.

Where did you get this file?

I also tried to add int led, but that gave the following errors

Well, of course. The way your code is written, led is supposed to be an instance of some class. Which class it is supposed to be an instance of is not clear.

Why bother with an LED class, when turning an LED on or off is so simple?

A finite state machine is not a library, it is a concept.

Throw out that library, read some general stuff about how a state machine operates, and then start from scratch. Trust me, it's actually easier that way than using some obtuse library that you have no clue how to operate properly.

PaulS
The led.h was the one that was shown in the comments at the start!
I am actually going to switch a relay, but as the example that I tried was to switch an led I left it as such, as the procedure would be the same for switching a relay module. This is an experiment to see if using FSM would be suitable for the project I am working on. (See my posts - Programming Questions > Problem with checking level sensor during Alarm on period using DS3231).

Jiggy-Ninja
Yes it is a concept! As I am fairly new to programming I am finding it difficult to grasp. Have you any info/links on this subject?

I had a lot of difficulty at first as although I installed the libraries required it still required another library, namely Wprogram.h.
I enventually found that you can use Arduino.h instead and the example program ran OK.

The Arduino IDE changed about 5 years ago, with WProgram.h being replaced by Arduino.h

If you see a library refering to WProgram.h, it is ancient, and you should updated by editing the
library.

Neither WProgram.h or Arduino.h are libraries, they are just include files.

The led.h was the one that was shown in the comments at the start!

The name of the library is far less important than where you got it.

but as the example that I tried was to switch an led

It used an unnecessarily complex way of turning the pin off and on. For testing purposes, simpler is usually better.

This is a good start point..

http://www.gammon.com.au/forum/?id=12316

Not sure what's complex about irrigating a garden.

1 - read the time from your real-time clock
2 - work out what's supposed to be on right now
3 - if anything is on that shoudn't be, turn it off
4 - if anything is not on that should be, turn it on