from __future__ import print_function from Adafruit_Thermal import * import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library import random import time #For sleep function from textwrap3 import wrap def button_callback(channel): print("Button was pushed!") poem = verb_list[random.randint(0, len(verb_list)-1)] \ + adjective_list[random.randint(0, len(adjective_list)-1)] \ + noun_list[random.randint(0, len(noun_list)-1)] # poem = noun_list[random.randint(0, len(noun_list)-1)] \ # + verb_list[random.randint(0, len(verb_list)-1)] \ # + adverb_list[random.randint(0, len(adverb_list)-1)] \ # + preposition_list[random.randint(0, len(preposition_list)-1)] \ # + "the " + adjective_list[random.randint(0, len(adjective_list)-1)] \ # + place_list[random.randint(0, len(place_list)-1)] thermal_print_ln(" ") thermal_print_ln(" ") thermal_print_ln("Here is computationally") thermal_print_ln("conjured random advice") thermal_print_ln("from the universe.") thermal_print_ln("Absorb it in your hyperconscious.") largeFontOn() foo = wrap(poem, 16) poem = '' for line in foo: poem = poem + '\n' + line # thermal_print_ln(noun_list[random.randint(0, len(noun_list)-1)] + verb_list[random.randint(0, $ # thermal_print_ln(adverb_list[random.randint(0, len(adverb_list)-1)] + preposition_list[random.$ # thermal_print_ln('the ' + place_list[random.randint(0, len(place_list)-1)]) # thermal_print_ln(" ") # largeFontOn() thermal_print(poem) thermal_print_ln(" ") thermal_print_ln(" ") thermal_print_ln(" ") thermal_print_ln(" ") thermal_print_ln(" ") largeFontOff() time.sleep(10) # Print lines of text in buffer def thermal_print_ln(msg): printer.println(msg+"\n") # Send text but don't print - you need to send a # newline (\n) character to empty buffer & print. # This enables mixed print modes on same line. def thermal_print(msg): printer.println(msg) def doubleHeightOn(): printer.println("\x1B\x21\x10") def doubleHeightOff(): global print_mode printer.println("\x1B\x21\x00") def smallFontOn(): printer.println("\x1B\x21\x01") def smallFontOff(): printer.println("\x1B\x21\x00") def boldOn(): printer.println("\x1B\x45\x01") def boldOff(): printer.println("\x1B\x45\x00") def wideOn(): printer.println("\x1B\x0E") def wideOff(): printer.println("\x1B\x14") def inverseOn(): printer.println("\x1B\x21\x02") def inverseOff(): def upsideDownOn(): printer.println("\x1B\x7B\x01") def upsideDownOff(): printer.println("\x1B\x7B\x00") def underlineOn(): printer.println("\x1B\x2D\x02") def underlineOff(): printer.println("\x1B\x2D\x00") def largeFontOn(): printer.println("\x1D\x21\x11") def largeFontOff(): printer.println("\x1D\x21\x00") def leftAlign(): printer.println("\x1B\x61\x00") def centreAlign(): printer.println("\x1B\x61\x01") def rightAlign(): printer.println("\x1B\x61\x02") # prints test page def printerTest(): printer.println("\x12\x54") # resets the printer to default values def printerReset(): printer.println("\x1B\x40") GPIO.setwarnings(False) # Ignore warning for now GPIO.setmode(GPIO.BOARD) # Use physical pin numbering GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial$ printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5) # press button A to activate demo # increase printing temperature and time printer.println("\x1B\x37\x07\xFF\xFF") noun_list = ["mystery ", "love ", "rainbow ", "buddha-nature ", "culture ", "puzzle ", "mystery ", $ verb_list = ["invoke ", "bless ", "trick ", "fake ", "love ", "repair ", "assemble ", "illustrate "$ adjective_list = ["metaphorical ", "theoretical ", "funny ", "absurd ", "dangerous ", "original ", $ GPIO.add_event_detect(16,GPIO.RISING,callback=button_callback) message = input("Press enter to quit\n\n") # Run until someone presses enter GPIO.cleanup()