clear.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (c) 2017 Adafruit Industries
  2. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  3. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  4. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  5. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  7. # THE SOFTWARE.
  8. # This example is for use on (Linux) computers that are using CPython with
  9. # Adafruit Blinka to support CircuitPython libraries. CircuitPython does
  10. # not support PIL/pillow (python imaging library)!
  11. import board
  12. import busio
  13. from PIL import Image, ImageDraw
  14. import adafruit_ssd1306
  15. # Create the I2C interface.
  16. i2c = busio.I2C(board.SCL, board.SDA)
  17. # Create the SSD1306 OLED class.
  18. disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
  19. # Clear display.
  20. disp.fill(0)
  21. disp.show()
  22. # Create blank image for drawing.
  23. # Make sure to create image with mode '1' for 1-bit color.
  24. width = disp.width
  25. height = disp.height
  26. image = Image.new("1", (width, height))
  27. # Get drawing object to draw on image.
  28. draw = ImageDraw.Draw(image)
  29. # Draw a black filled box to clear the image.
  30. draw.rectangle((0, 0, width, height), outline=0, fill=0)