Today, we continued to talk about debouncing and some other ways we can use it. We also talked about embedded systems and how they use state machines. In the lab, we began to build libraries of functions so we can use it in the future to simplify complicated code.
There two pieces of code do the exact same thing!
static enum {INITIAL, LOCKED, ONE_RIGHT, TWO_RIGHT, OPEN};
myState = INITIAL;
if (myState == INITIAL){
// initialization code goes here
myState = LOCKED;
} else if (myState == LOCKED){
if (event == 1){
// respond to LOCKED/1 pair
}
} else if (myState == ONE_RIGHT){
Despite that, this one, the second one, is much easier to read.
static enum {INITIAL, LOCKED, ONE_RIGHT, TWO_RIGHT, OPEN};
myState = initial;
switch (myState){
case INITIAL:
// initialization code goes here
myState = LOCKED
break;
case LOCKED:
switch (event){
case 1:
// respond to LOCKED/1 pair
break;}
case ONE_RIGHT: