Cycling Through Messages on a Display

Hello All,

I'm looking for ideas to optimize code, and also change how the messages are displayed.

Starting Code:

int savedTime, passedTime;
int totalTime = 2000;

void setup(){
  
  size(600,600);
  smooth();
 
}

void draw(){
  
  background(0);
  fill(255,255,255);
  rect(100,300, 350,100, 5);
  
  passedTime = millis() - savedTime;      // delay of two seconds before displaying a message
    
  if(passedTime >= totalTime)
  {
     
    delay(1000);
    
    byte switch1 = byte(random(2));       // substitue software switches to replace Arduino inputs
    byte switch2 = byte(random(2));         
    byte switch3 = byte(random(2));
    byte switch4 = byte(random(2));
  
    byte switchCondition = byte((switch1 + switch2 + switch3 + switch4));
    messageCenter(switchCondition);
    
  } 
}

void messageCenter(byte switchCondition){
  
  String[] troubleMessages = {"Hello", "How are you?  ", "What is going on?", "Not Much!"};
  fill(0,0,0);
  textSize(22);


  if(passedTime >= totalTime)
  {
        
    switch(switchCondition) 
    {
        case 1: 
        text(troubleMessages[0], 110,350); 
        break;
  
        case 2: 
        text(troubleMessages[1], 110,350);
        break;

        case 3: 
        text(troubleMessages[2], 110,350);
        break;
  
        default:
        text(troubleMessages[3], 110,350);
        break;
     }
    
   }
}

What I would like to happen is:

Display one, or more messages dependent on which switch is set HIGH.

If more than one switch is set HIGH, I would like the first message to be displayed
for two seconds, then cycle to the next message.

My thought is to arrange an array representing BINARY BITS for each switch, and then
use a subroutine to decipher the bit pattern and determine the messages that need to
be displayed.

For example, if I had an 8 bit word, I could assign bit 0 to display, "Hello"; bit 1 to display "How"; etc.

0000 0001 = "Hello"

0000 0010 = "How"

0000 0011 = "Hello", (wait two seconds), "How"

The order is not important.

The Arduino will read the pin inputs, and Processing will receive the data via serialEvent() into
an array.

I can assign delimited values to variables, and then use "IF Statements" to call specific subroutines,
or "SWITCH/CASE", however there must be an easier way?

My thought process:

switch1=rxArray[0];

switch2=rxArray[1];

switch3=rxArray[2];

switch4=rxArray[3];


if (rxArray[0]==1)text("Hello", 100,100);


if (rxArray[1]==1)text("How", 100,100);


if (rxArray[2]==1){

    text("Hello", 100,100);

    //timer code

    text("How",100,100);

}

With 8 different switches, the combinations of IF Statements in the code would be unreal.

Any ideas? Is BINARY() the correct path to research, or can you suggest another angle?

Thanks!

This looks like a Processing question rather than an Arduino one. The Arduino side sounds simple. Use a for loop to read each input and set the appropriate bit in a variable then send the result to Processing.

This is definitely more of Processing question. I know there are several members here that are fluent with
the code, and I prefer the layout of this forum over the Processing forum.

Maybe that's a poor excuse, but I'm also too lazy to create an account over "there". I guess I'll sign up and do the right thing... :frowning: