switch statement / bools to change modes?

Hi there

I’m working on an application which has four different modes - I want to control these with sound (the user claps and we go to the next mode). I’ve got my different modes working independently, my audio input working great (if a certain volume is reached I want it to switch to the next mode), but I’m at a loss when it comes to putting them together.

I think I might need to use a switch statement but am unsure and frankly am having trouble understanding them in relation to my problem - can it be done using bools and if statements? I’m generally a bit confused about it – any ideas would be very welcome! Thanks

Hi

I sorted it out in the end, using a combination of if statements and boolean switches (is this what they are called? i’m not sure - they look like this anyway - bMode_01 = !bMode_01;).

It seems for me to solve an OF problem on my own I first have to put it out on the forum.

:slight_smile:

hey there,

bools are not ideal, i don’t think… the approach i tend to use is an enum, which is a built-in C type. like this:

testApp.h:

  
typedef enum {  
STATE_1, // these can have any name you want, eg STATE_CLAP etc  
STATE_2,  
STATE_3  
} State;  
  
class testApp  
{  
  ...  
  
  State myState;  
};  

testApp.cpp:

  
...  
void testApp::update()  
{  
  ...  
  switch( myState )  
  {  
    case STATE_1:  
      ...  
      break;  
    case STATE_2:  
      ...  
      break;  
    case STATE_3:  
      ...  
      break;  
  }  
  ...  
}