-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patholed-wuerfel.py
More file actions
48 lines (41 loc) · 1.23 KB
/
oled-wuerfel.py
File metadata and controls
48 lines (41 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import adafruit_ssd1306
from PIL import Image, ImageDraw, ImageFont
from random import randint
import RPi.GPIO as gpio
import digitalio
import time
import board
# define pins
gpio.setmode(gpio.BCM)
channel = 23
gpio.setup(channel, gpio.IN, pull_up_down=gpio.PUD_UP)
RESET_PIN = digitalio.DigitalInOut(board.D4)
i2c = board.I2C()
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3C, reset=RESET_PIN)
# clear display
oled.fill(0)
oled.show()
# import font
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 64)
# print ?
imageBegin = Image.new("1", (oled.width, oled.height))
ImageDraw.Draw(imageBegin).text((40, 0), "?", font=font, fill=255)
oled.image(imageBegin)
oled.show()
# generate images
numbers = []
for i in range(1, 7):
image = Image.new("1", (oled.width, oled.height))
ImageDraw.Draw(image).text((40, 0), str(i), font=font, fill=255)
numbers.append(image)
while True:
if gpio.input(channel) == 0:
while True:
oled.image(numbers[randint(0, 5)])
oled.show()
time.sleep(0.01)
if gpio.input(channel) == 1:
oled.image(numbers[randint(0, 5)])
oled.show()
time.sleep(0.5)
break