Hello
I've got a problem which i think is related to a scope issue. But i'm completely blank and have tried a lot of different stuff to get rid of the compiler error. Here is the code of a simple state machine:
/* statemachine */
enum {ms_idle,ms_start,ms_stop};
typedef struct{
int state,oldstate;
int time;
}smtype;
void sm_update(smtype *p);
smtype mission;
void setup(){
Serial.begin(9600);
mission.state=ms_idle;
}
void loop(){
sm_update(&mission);
switch(mission.state){
case ms_idle:
Serial.print("state idle");
delay(5000);
mission.state=ms_start;
break;
case ms_start:
Serial.print("state start");
delay(5000);
mission.state=ms_stop;
break;
case ms_stop:
Serial.print("state stop");
delay(5000);
break;
}
}
void sm_update(smtype *p){
if (p->state!=p->oldstate){
p->time=0;
p->oldstate=p->state;
}
else {
p->time++;
}
}
This results in a compiler error:
statemachine:1: error: variable or field 'sm_update' declared void
statemachine:1: error: 'smtype' was not declared in this scope
statemachine:1: error: 'p' was not declared in this scope
The compiler is complaining over the void sm_update(smtype *p)
function.
Hope someone can give me a clue what's wrong in this code.
Cheers