Go Down

Topic: Searching for a Random Number and Blinking LED (Read 809 times) previous topic - next topic


I want to create a sketch that creates an array of random integers between 1 and 50 and the size of the array should be 20 integers. So 20 random integers between 1 and 50.

Then I want the sketch to search for a particular value in that array. So let's say the value of 25. If the value is found in the array then I need the LED on pin 13 to blink 3 times. And if the value does not occur in the array, turn the pin 13 LED on for two seconds.

Delay for three seconds and then the process should repeat from the beginning.


Apr 23, 2015, 10:50 pm Last Edit: Apr 23, 2015, 10:52 pm by PaulRB
Wierd! Is this a school/college assignment?

How does the sketch know what value to search for?


I am trying to first figure out how to create an array with a length of 20 integers that selects random numbers. I am very new to Arduino, but I have something like this:

randNumber = random(1,50);
int myArray[20] = {randNumber};

will that give me an array of 20 ingegers from 1-50?


Apr 24, 2015, 06:49 am Last Edit: Apr 24, 2015, 06:52 am by siutoejai

a random number between min and max-1 (long)

only from 1 to 49

try it out

use Serial.println to print your array

you will see the result


You might like to look at the use if the for loop wrt arrays, here.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0




To answer your question, No.

randnumber just creates one random  number. Your initiaiization of a 21 element array only assigns one value. And yes, I said 21 element. Arduino arrays start at 0.

Also, although it hasn't been mentioned, this will produce the same sequence of random numbers ech time the Arduino restarts. Look up randomseed in the reference.

The other member's advice of checking out the reference of for loops will also be very useful...

Go Up