image_timed.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (c) 2014 Adafruit Industries
  2. # Author: Tony DiCola
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining a copy
  5. # of this software and associated documentation files (the "Software"), to deal
  6. # in the Software without restriction, including without limitation the rights
  7. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. # copies of the Software, and to permit persons to whom the Software is
  9. # furnished to do so, subject to the following conditions:
  10. #
  11. # The above copyright notice and this permission notice shall be included in
  12. # all copies or substantial portions of the Software.
  13. #
  14. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. # THE SOFTWARE.
  21. from PIL import Image
  22. import time
  23. import ST7735 as TFT
  24. import Adafruit_GPIO as GPIO
  25. import Adafruit_GPIO.SPI as SPI
  26. WIDTH = 128
  27. HEIGHT = 160
  28. SPEED_HZ = 4000000
  29. # Raspberry Pi configuration.
  30. DC = 24
  31. RST = 25
  32. SPI_PORT = 0
  33. SPI_DEVICE = 0
  34. # BeagleBone Black configuration.
  35. #DC = 'P9_15'
  36. #RST = 'P9_12'
  37. #SPI_PORT = 1
  38. #SPI_DEVICE = 0
  39. # Create TFT LCD display class.
  40. disp = TFT.ST7735(
  41. DC,
  42. rst=RST,
  43. spi=SPI.SpiDev(
  44. SPI_PORT,
  45. SPI_DEVICE,
  46. max_speed_hz=SPEED_HZ))
  47. # Initialize display.
  48. disp.begin()
  49. # Load an image.
  50. print('Loading image...')
  51. image = Image.open('cat.jpg')
  52. # Resize the image and rotate it so matches the display.
  53. image = image.rotate(90).resize((WIDTH, HEIGHT))
  54. print('Press Ctrl-C to exit')
  55. while(True):
  56. # Draw the image on the display hardware.
  57. print('Drawing image')
  58. start_time = time.time()
  59. disp.display(image)
  60. end_time = time.time()
  61. print('Time to draw image: ' + str(end_time - start_time))
  62. disp.clear((0, 0, 0))
  63. disp.display()