ESP8266/Arduino C++: Working with random numbers and CASE/SWITCH

Very elementary, but this might help someone..  Simply a random number generator and make a string variable contain the text of a number.    Also experimenting with concatenate of string variable. 

 

 

 

int MyVal = 23;
int MyRand = 0;
String myData = String(25);
String MyCase = String(15);



void setup()
{
  Serial.begin(9600);
  

  
}



void loop()
{

  

MyVal++;
MyRand = random(10, 15);
    

myData = "Testing";
Serial.println(myData);
  
myData = myData + " Output";
Serial.println(myData);
  
myData = myData + " - " + MyVal;
Serial.println(myData);

myData = myData + " - " + MyRand;
Serial.println(myData);
  
  switch (MyRand) {
   case 10:
   MyCase = "TEN";
    break;


      case 11:
   MyCase = "ELEVEN";
   break;


      case 12:
   MyCase = "TWELVE";
   break;


      case 13:
   MyCase = "THIRTEEN";
   break;


      case 14:
   MyCase = "FOURTEEN";
   break;


      case 15:
   MyCase = "FIFTEEN";
   break;

      
  }
  
   
   myData = myData + " - " + MyCase;
Serial.println(myData);
  
  delay(500); 
  
}

 

Comments are closed