Created
November 10, 2016 14:56
-
-
Save jetpax/701d65c3270bd2c150447f67c44017a2 to your computer and use it in GitHub Desktop.
Function pointer state machine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment