Buzzword bingo is everyone's favourite game, right? So as a way of making it a little more fun I want to produce a random buzzword from a list then the player has to slip it into a meeting whilst keeping a straight face. What better way to use your arduino? Probably loads but hey ho.
So the problem is I'm a bit useless at this. the approach I'm taking is to generate a random number then to use that number to look up in an array and to pick fro a list of phrase's. I'm struggling to keep the monkey's under the table here. Is this a good approach?
So far I've got my head round generating a random number using an analogue pin and can prove that. Code below...
Next up is the lookup in an array. Before I draw a line in that sand can anyone confirm that this is a sound approach before I try and work out what these array's do? After that it'll be a mess about with the code and use a big button to do the generation rather than the current format.
The follow on from that question then is it normal to use a number (index?) to return a value from an array?
But be sure to place that array in PROGMEM. Which is not that straight forward... Otherwise you will run out of memory pretty quick.
Alternatively use a SD-card. That way it's even possible to update the list without reprogramming it. Just make a text file (.txt) with all the words, each on a new line. At the start go trough the whole list to count how many words there are (by looping over all chars and counting the new lines). Now you can use random to pick a word. And to fetch the word, you go over the file and count that number of new lines. (A new line is just a character so the Arduino has no notion of line numbers by itself.)
Two extra points:
Add a button (bonus tip: a library like Bounce2 makes it dead easy) to generate a new word instead of resetting the Arduino. Although the reset is indeed a pretty easy solution as well
Even though you only use A1 to generate a random seed, use a constant for that as well. That way it's easy to sport at the top you already "used" that pin.