hrheingold

Untitled

Dec 4th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. from __future__ import print_function
  2. from Adafruit_Thermal import *
  3. import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
  4. import random
  5. import time #For sleep function
  6. from textwrap3 import wrap
  7.  
  8. def button_callback(channel):
  9. print("Button was pushed!")
  10.  
  11. poem = verb_list[random.randint(0, len(verb_list)-1)] \
  12. + adjective_list[random.randint(0, len(adjective_list)-1)] \
  13. + noun_list[random.randint(0, len(noun_list)-1)]
  14.  
  15. # poem = noun_list[random.randint(0, len(noun_list)-1)] \
  16. # + verb_list[random.randint(0, len(verb_list)-1)] \
  17. # + adverb_list[random.randint(0, len(adverb_list)-1)] \
  18. # + preposition_list[random.randint(0, len(preposition_list)-1)] \
  19. # + "the " + adjective_list[random.randint(0, len(adjective_list)-1)] \
  20. # + place_list[random.randint(0, len(place_list)-1)]
  21. thermal_print_ln(" ")
  22. thermal_print_ln(" ")
  23. thermal_print_ln("Here is computationally")
  24. thermal_print_ln("conjured random advice")
  25. thermal_print_ln("from the universe.")
  26. thermal_print_ln("Absorb it in your hyperconscious.")
  27. largeFontOn()
  28.  
  29. foo = wrap(poem, 16)
  30. poem = ''
  31. for line in foo:
  32. poem = poem + '\n' + line
  33.  
  34. # thermal_print_ln(noun_list[random.randint(0, len(noun_list)-1)] + verb_list[random.randint(0, $
  35. # thermal_print_ln(adverb_list[random.randint(0, len(adverb_list)-1)] + preposition_list[random.$
  36. # thermal_print_ln('the ' + place_list[random.randint(0, len(place_list)-1)])
  37. # thermal_print_ln(" ")
  38. # largeFontOn()
  39. thermal_print(poem)
  40. thermal_print_ln(" ")
  41. thermal_print_ln(" ")
  42. thermal_print_ln(" ")
  43. thermal_print_ln(" ")
  44. thermal_print_ln(" ")
  45. largeFontOff()
  46. time.sleep(10)
  47.  
  48. # Print lines of text in buffer
  49. def thermal_print_ln(msg):
  50. printer.println(msg+"\n")
  51.  
  52. # Send text but don't print - you need to send a
  53. # newline (\n) character to empty buffer & print.
  54. # This enables mixed print modes on same line.
  55. def thermal_print(msg):
  56. printer.println(msg)
  57.  
  58. def doubleHeightOn():
  59. printer.println("\x1B\x21\x10")
  60.  
  61. def doubleHeightOff():
  62. global print_mode
  63. printer.println("\x1B\x21\x00")
  64.  
  65. def smallFontOn():
  66. printer.println("\x1B\x21\x01")
  67.  
  68. def smallFontOff():
  69. printer.println("\x1B\x21\x00")
  70.  
  71. def boldOn():
  72. printer.println("\x1B\x45\x01")
  73.  
  74. def boldOff():
  75. printer.println("\x1B\x45\x00")
  76.  
  77. def wideOn():
  78. printer.println("\x1B\x0E")
  79.  
  80. def wideOff():
  81. printer.println("\x1B\x14")
  82.  
  83. def inverseOn():
  84. printer.println("\x1B\x21\x02")
  85.  
  86. def inverseOff():
  87. def upsideDownOn():
  88. printer.println("\x1B\x7B\x01")
  89.  
  90. def upsideDownOff():
  91. printer.println("\x1B\x7B\x00")
  92.  
  93. def underlineOn():
  94. printer.println("\x1B\x2D\x02")
  95.  
  96. def underlineOff():
  97. printer.println("\x1B\x2D\x00")
  98.  
  99. def largeFontOn():
  100. printer.println("\x1D\x21\x11")
  101.  
  102. def largeFontOff():
  103. printer.println("\x1D\x21\x00")
  104.  
  105. def leftAlign():
  106. printer.println("\x1B\x61\x00")
  107.  
  108. def centreAlign():
  109. printer.println("\x1B\x61\x01")
  110.  
  111. def rightAlign():
  112. printer.println("\x1B\x61\x02")
  113.  
  114. # prints test page
  115. def printerTest():
  116. printer.println("\x12\x54")
  117.  
  118. # resets the printer to default values
  119. def printerReset():
  120. printer.println("\x1B\x40")
  121.  
  122. GPIO.setwarnings(False) # Ignore warning for now
  123. GPIO.setmode(GPIO.BOARD) # Use physical pin numbering
  124. GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 10 to be an input pin and set initial$
  125.  
  126. printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
  127.  
  128. # press button A to activate demo
  129. # increase printing temperature and time
  130. printer.println("\x1B\x37\x07\xFF\xFF")
  131.  
  132. noun_list = ["mystery ", "love ", "rainbow ", "buddha-nature ", "culture ", "puzzle ", "mystery ", $
  133. verb_list = ["invoke ", "bless ", "trick ", "fake ", "love ", "repair ", "assemble ", "illustrate "$
  134. adjective_list = ["metaphorical ", "theoretical ", "funny ", "absurd ", "dangerous ", "original ", $
  135.  
  136.  
  137. GPIO.add_event_detect(16,GPIO.RISING,callback=button_callback)
  138.  
  139.  
  140. message = input("Press enter to quit\n\n") # Run until someone presses enter
  141.  
  142. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment