Creating a random Haiku Generator

So I am new to programming in general and I'm taking a class that requires it. For a project I am wanting to create a random Haiku generator using two or three buttons. I want the first button to give a random 5 syllable phrase, the second button to generate a random 7 syllable phrase, and the third for the last 5 syllable phrase. These phrases will be pre-written so I don't need each word to be random. The Haiku will just need to appear on the serial monitor and I may want a fourth button to clear the screen.

If I could work it out so one button press does the entire Haiku then that could work great too but it's not necessary. I don't need the whole code written out for me, but I would greatly appreciate it if someone could get me on the right track (especially for the random generation part).

Start by looking at the random() and randomSeed() functions

How many different phrases of each kind are required ?

What do you know about arrays (HINT) ?

I assume that you know how to read and test the state of an input, or do you ?

What have you tried so far ?

To start I think about 10 of each phrase would work.

I haven't really tried anything yet but I know the basic function to get a phrase with the button push. My main issue is randomizing the phrases.

Also I am not sure I understand the 4th question but I know how to test the program and find the errors if thats what you mean.

(Again sorry for seeming stupid but I am new to this and my brain is having issues understanding some of the code)

My main issue is randomizing the phrases.

As I said

Start by looking at the random() and randomSeed() functions

As to the 4th question, do you mean ?

I assume that you know how to read and test the state of an input, or do you ?

If so, then no, it has nothing to do with program errors and everything to do with determining that a button has been pressed and taking action as a result

For instance, do you know how to determine that a button has become pressed rather than when it is pressed ?

Generate a seed
Use it to look up a row
That is what you need

Could you possibly show me an example of this? I don't know how to have it look up a row.

const char * phrases[] = {"Hello World", "Goodnight Vienna", "Merry Christmas"};
const byte phraseCount = sizeof(phrases) / sizeof(phrases[0]);

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  randomSeed(analogRead(0));
}

void loop()
{
  byte chosenPhrase = random(phraseCount);
  Serial.println(phrases[chosenPhrase]);
  delay(1000);
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.