Go Down

Topic: Coding help, randomize. (Read 76 times) previous topic - next topic



I'm trying to get my matrix to show different images every time the sound detector picks up sound. i got this code and it works showing 1 image

if (statusSensor > 450){
  Select = 2;}

The question is: How do i continue the code from here when adding number 3,4 and 5?
I want them to show in random order every time the sound detector picks up sound (so that it doesn't only show 2.

Please help! :)


We are glad to help, if you will explain more clearly what you want to do, and post the code, after carefully reading and following the instructions in the "How to use this forum" post.


Put the numbers that you want to select in an array
Use the random() function to provide a number of appropriate value to be used as the array index
Get a number from the array using the random index number

Look at the random() and randomSeed() functions in the Arduino reference before going too far with the project
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Go Up