Libraries
\ FSM
Reference for Wiring version 1.0 Build 0100+ If you have a previous version, use the reference included with your software. If see any errors or have any comments, let us know.
Name |
FSM |
Examples |
#include <FiniteStateMachine.h>
#include <Button.h>
#include <LED.h>
const byte NUMBER_OF_STATES = 4;
State On = State(ledOn);
State Off = State(ledOff);
State FadeIn = State(ledFadeIn);
State FadeOut = State(ledFadeOut);
FSM ledStateMachine = FSM(On);
Button button = Button(12,BUTTON_PULLUP);
LED led = LED(11);
byte buttonPresses = 0;
void setup(){ }
void loop()
{
if (button.uniquePress())
{
buttonPresses = ++buttonPresses % NUMBER_OF_STATES;
switch (buttonPresses)
{
case 0: ledStateMachine.transitionTo(On); break;
case 1: ledStateMachine.transitionTo(Off); break;
case 2: ledStateMachine.transitionTo(FadeIn); break;
case 3: ledStateMachine.transitionTo(FadeOut); break;
}
}
ledStateMachine.update();
}
void ledOn(){ led.on(); }
void ledOff(){ led.off(); }
void ledFadeIn(){ led.fadeIn(500); }
void ledFadeOut(){ led.fadeOut(500); }
|
Description |
Set the initial state of this Finite State Machine. |
Syntax |
FSM(current)
FiniteStateMachine(current)
|
Methods |
|
Parameters |
current |
The initial state of the FSM |
|
Returns |
None |
Usage |
Application |
Updated on July 07, 2011 11:10:15pm PDT