Little Box of Haiku

Following on from my Little Box of Poems – which printed a random poem on till-roll (and which also inspired Carrie Anne Philbin’s Little Box of Geek) – I present: The Little Box of Haiku.

It’s made from a RaspberryPi and one of Pimoroni’s lovely Displayotron 3000 LCD display / button gizmos.

You push a button and this Python script generates a random haiku from a set of 5, 7 and 5 syllable sentences.

Enjoy!


#!/usr/bin/env python
import time
import dot3k.lcd as lcd
import random
import dot3k.backlight as backlight
import dot3k.joystick as j
import signal

backlight.rgb(0,0,255)
lcd.set_cursor_position(0,0)
lcd.write("@blogmywiki's   amazing random  haiku machine")

five_syllable = ['Cat crouches     wisely', 'Dog wags tail in hope', 'Leaves fall on   the ground', 'Apples are       falling', 'A child stops to look']
seven_syllable = ['No-one knows why they come here', 'The moon rises   unnoticed', 'Stars are       falling to Earth now', 'The grass is moist underfoot', 'Buttercups hide in the shade']

time.sleep(3)

lcd.clear()
lcd.write("Press button to create your     personal haiku")

while True:

        @j.on(j.BUTTON)
        def handle_button(pin):
          backlight.rgb(255,255,255)
          lcd.clear()
          line1 = random.choice(five_syllable)
          line2 = random.choice(seven_syllable)
          line3 = random.choice(five_syllable)
          lcd.set_cursor_position(0,0)
          lcd.write(line1)
          time.sleep(5.5)
          lcd.clear()
          lcd.set_cursor_position(0,0)
          lcd.write(line2)
          time.sleep(5.5)
          lcd.clear()
          lcd.set_cursor_position(0,0)
          lcd.write(line3)
          time.sleep(5.5)
          backlight.rgb(0,255,0)
          lcd.clear()
          lcd.set_cursor_position(0,0)
          lcd.write("Press button to create your personal haiku")
        # Prevent the script exiting!
        signal.pause()
This entry was posted in poetry, Raspberry Pi and tagged , , , . Bookmark the permalink.

Leave a Reply