Skip to content

Instantly share code, notes, and snippets.

@jetpax
Created November 10, 2016 14:56
Show Gist options
  • Save jetpax/701d65c3270bd2c150447f67c44017a2 to your computer and use it in GitHub Desktop.
Save jetpax/701d65c3270bd2c150447f67c44017a2 to your computer and use it in GitHub Desktop.

Revisions

  1. jetpax created this gist Nov 10, 2016.
    44 changes: 44 additions & 0 deletions LEDflashFSM.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    typedef void (*FSM)(void);

    /*****************************************************
    * FSM: test pin
    * States */

    void smTestPinInit(void);
    void smTestPinLo(void);
    void smTestPinHi(void);

    //FSM Variables

    unsigned long test_tmr;

    //Initial state
    FSM testPinFSM = smTestPinInit;
    /******************************************************
    State functions */

    void smTestPinInit(void) {
    DDRD |= 0x80; // ***DEBUG*** toggle test pin
    testPinFSM = smTestPinLo; // change state
    test_tmr = millis();
    }

    void smTestPinLo(void) {

    if (millis() - test_tmr >= 30){
    test_tmr = millis();
    PORTD &= ~0x80; // ***DEBUG*** toggle test pin
    testPinFSM = smTestPinHi; // change state
    }
    }

    void smTestPinHi(void) {

    if (millis() - test_tmr >= 50){
    test_tmr = millis();
    PORTD |= 0x80; // ***DEBUG*** toggle test pin
    testPinFSM = smTestPinLo; // change state
    }
    }