Hiya all, i seem to be having trouble with the code i have included below where by i set the states upon different conditions however this seems to work twice and after that i cannot get any transition.
The state changes as i have added a serial print and i see that the state changes yet the next state does not run and i am unsure what i am doing wrong here any advice or guidance?
Control_Point Control_Point;
enum State { //Our states we have
INITIALISING,
IDLE,
STARTING,
CAPTURING,
STOPPING,
Nothing
} state;
void setup() {
Serial.begin(9600);
Serial.println("Starting...");
pinMode(ledPin, INPUT);
pinMode(motionSensor, INPUT);
pinMode(functionButton, INPUT);
state = INITIALISING;
Control_Point.begin(true);
attachInterrupt(digitalPinToInterrupt(functionButton), setState, CHANGE);
delay(1000);
Serial.println("Started");
}
void loop() {
bool buttonTrigger = Control_Point.check_Button(buttonState);
switch (state) {
case INITIALISING:
Serial.println("Initialising.");
state = IDLE;
break;
case IDLE:
if (buttonTrigger) {
Serial.println("Button Triggered!");
Control_Point.Sound(0, 3900, 0);
state = STARTING;
}
break;
case STARTING:
if (Control_Point.Sound(0, 3900, 0) == 0) {
Serial.println("Starting Finished!");
state = CAPTURING;
}
break;
case CAPTURING:
if(buttonTrigger){
Serial.println("Button Reverse Trigger!");
Control_Point.Sound(2, 3900, 0);
state = STOPPING;
}
Serial.println(state);
break;
case STOPPING:
if(Control_Point.Sound(2, 3900, 0) == 0){
Serial.println("Sound Finished!");
state = IDLE;
}
break;
}
attachInterrupt(digitalPinToInterrupt(19), setState, CHANGE);
}
Thank you in advance.