Skip to content

Instantly share code, notes, and snippets.

@mcavalcantib
Created March 21, 2024 15:32
Show Gist options
  • Select an option

  • Save mcavalcantib/4664c3345e61c3b96929010c724dc57b to your computer and use it in GitHub Desktop.

Select an option

Save mcavalcantib/4664c3345e61c3b96929010c724dc57b to your computer and use it in GitHub Desktop.

Revisions

  1. mcavalcantib created this gist Mar 21, 2024.
    44 changes: 44 additions & 0 deletions state_machine.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    #include <stdio.h>

    long stateStart = 0;

    // fun_ptr is a pointer to function fun()
    void (*UpdateFunction)(void);

    void ManualMode(){
    //Acoes de exibir e controlar o modo manual
    if(selectButton && option == 2){ //opção 2 cancelar
    UpdateFunction = &MainMenu;
    }
    }

    void MainMenu(){
    // funções de exibir as opções na tela
    //...
    if(selectButton && option == 1){ // opção 1 manual
    UpdateFunction = &ManualMode;
    }
    }

    void SplashScreen()
    {
    if(millis() - stateStart < 3000){
    PrintSplash();
    }else{
    UpdateFunction = &MainMenu;
    }
    }


    int main()
    {
    //setup
    UpdateFunction = &SplashScreen;

    //loop
    while(1){
    UpdateFunction();
    }

    return 0;
    }