Skip Navigation

Contextual Learning Portal

Random Poetry Generator

Basics

  • Project TitleRandom Poetry Generator
  • ThemeCoding, Arduino, Creativity
  • Submitted ByJennifer Leonard
  • OrganizationThe Skills Library
  • Brief DescriptionA random-poetry generator using an Arduino board and circuit based on the Snap Circuits "Snapino" set. Turn the crank on a generator, then pause, and random words appear on the computer screen to create a random poem. The faster you turn the crank, the more poetry you get.

    The program is pre-written, including an array of words for the random poetry, and participants can modify the program and array of words.
  •  /project648_7346/IMG_3813.JPG/project648_7346/Generator-Powered-Poetry.png/project648_7346/IMG_3814[1].JPG/project648_7346/IMG_0702.JPG
  • Materials / ResourcesSnap Circuits (TM) "Snapino" set
    Hand-cranked generator or motor (from another Snap Circuits or Thames & Kosmos set)
    Computer with Arduino software, as described in the Snapino set

Activity Sheets

  • Random Poetry Generator (Arduino Sketch)

    // first set up some variables that will be used in the program
    // r will be a random number that the program selects
    // s will be the previous random number... just because we do not want to use the same number twice in a row
    // delay1 is used to tell the program how much to pause between each step
    // the other fields define the pins on the micro-controller board and define a sensor reading that will measure how much power you get from the generator
    // the sensor reading could also pick up a reading from other sensors, such as a light sensor or motion detector
     

    long r;
    long s;
    int SensorReading = 0;
    int delay1=200;
    int i=1;

    const int ledPin =  10;
    const int button = 9;   
    const int mysensor = A0;

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

        pinMode(ledPin, OUTPUT);
        pinMode(mysensor,INPUT);   

      // if analog input pin 0 is unconnected, random analog
      // noise will cause the call to randomSeed() to generate
      // different seed numbers each time the sketch runs.
      // randomSeed() will then shuffle the random function.
     // or fill in a number to start the randomization, such as randomSeed(4)
      randomSeed(1);

    }

    void loop() {
      SensorReading = analogRead(mysensor); //Read the value of the A2 pin and assign that value to Val
     
      char* myPoemArray[]={
        "morning",
        "evening",
        "song",
        "harmony",
        "to",
        "from",
        "melody",
        "sun",
        "moon",
        "silent",
        "melody",
        "start",
        "over",
        "go",
        "return",
        "one",
        "may",
    };

    if (SensorReading<=300) {     
        digitalWrite(ledPin, HIGH);    //If the sensor meets the IF condition then turn on the LED

      // loop through this routine four times
      // choose a random number and then print that word number from the array of words
      // (unless it is a repeat of the previous word)

      int x = 1;
       for (int x = 0; x < 4; x = x + 1)
      {
      r = random(0, 17);
      if (r==s)
      { }
      else
       { Serial.print(myPoemArray[r]);
         Serial.print(" ");
         s=r;
         delay(delay1);
       }   
      }
       // after looping four times, move to the next line
       Serial.println(" ");
      }
      else {
        digitalWrite(ledPin, LOW);          //If anything else happens turn the LED off
        delay(delay1);
       }

    }

     


Tags = Science-Wednesdays | Arduino/Snapino | poetry | random | coding | Subject = Science | Grade Level = MS | Time Period = | Program/Funding = | NONE |
Direct website link to this project: http://resources21.org/cl/contextual.asp?projectnumber=648.7346