|
19 | 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20 | 20 | # THE SOFTWARE.
|
21 | 21 |
|
| 22 | +from PIL import Image, ImageDraw |
22 | 23 |
|
23 |
| -import time |
24 | 24 | import board
|
25 | 25 | import busio
|
26 | 26 | from digitalio import DigitalInOut, Direction, Pull
|
27 | 27 | import adafruit_ssd1306
|
28 |
| -from PIL import Image, ImageDraw, ImageFont |
29 | 28 |
|
30 | 29 | # Create the I2C interface.
|
31 | 30 | i2c = busio.I2C(board.SCL, board.SDA)
|
|
36 | 35 |
|
37 | 36 | # Input pins:
|
38 | 37 | button_A = DigitalInOut(board.D5)
|
| 38 | +button_A.direction = Direction.INPUT |
39 | 39 | button_A.pull = Pull.UP
|
| 40 | + |
40 | 41 | button_B = DigitalInOut(board.D6)
|
| 42 | +button_B.direction = Direction.INPUT |
41 | 43 | button_B.pull = Pull.UP
|
| 44 | + |
42 | 45 | button_L = DigitalInOut(board.D27)
|
| 46 | +button_L.direction = Direction.INPUT |
43 | 47 | button_L.pull = Pull.UP
|
| 48 | + |
44 | 49 | button_R = DigitalInOut(board.D23)
|
| 50 | +button_R.direction = Direction.INPUT |
45 | 51 | button_R.pull = Pull.UP
|
| 52 | + |
46 | 53 | button_U = DigitalInOut(board.D17)
|
| 54 | +button_U.direction = Direction.INPUT |
47 | 55 | button_U.pull = Pull.UP
|
| 56 | + |
48 | 57 | button_D = DigitalInOut(board.D22)
|
| 58 | +button_D.direction = Direction.INPUT |
49 | 59 | button_D.pull = Pull.UP
|
| 60 | + |
50 | 61 | button_C = DigitalInOut(board.D4)
|
| 62 | +button_C.direction = Direction.INPUT |
51 | 63 | button_C.pull = Pull.UP
|
52 | 64 |
|
53 | 65 |
|
|
65 | 77 | draw = ImageDraw.Draw(image)
|
66 | 78 |
|
67 | 79 | # Draw a black filled box to clear the image.
|
68 |
| -draw.rectangle((0,0,width,height), outline=0, fill=0) |
| 80 | +draw.rectangle((0, 0, width, height), outline=0, fill=0) |
69 | 81 |
|
70 | 82 |
|
71 | 83 | while True:
|
|
90 | 102 | draw.polygon([(30, 60), (40, 42), (20, 42)], outline=255, fill=1) #down filled
|
91 | 103 |
|
92 | 104 | if button_C.value: # button is released
|
93 |
| - draw.rectangle((20, 22,40,40), outline=255, fill=0) #center |
| 105 | + draw.rectangle((20, 22, 40, 40), outline=255, fill=0) #center |
94 | 106 | else: # button is pressed:
|
95 |
| - draw.rectangle((20, 22,40,40), outline=255, fill=1) #center filled |
| 107 | + draw.rectangle((20, 22, 40, 40), outline=255, fill=1) #center filled |
96 | 108 |
|
97 | 109 | if button_A.value: # button is released
|
98 |
| - draw.ellipse((70,40,90,60), outline=255, fill=0) #A button |
| 110 | + draw.ellipse((70, 40, 90, 60), outline=255, fill=0) #A button |
99 | 111 | else: # button is pressed:
|
100 |
| - draw.ellipse((70,40,90,60), outline=255, fill=1) #A button filled |
| 112 | + draw.ellipse((70, 40, 90, 60), outline=255, fill=1) #A button filled |
101 | 113 |
|
102 | 114 | if button_B.value: # button is released
|
103 |
| - draw.ellipse((100,20,120,40), outline=255, fill=0) #B button |
| 115 | + draw.ellipse((100, 20, 120, 40), outline=255, fill=0) #B button |
104 | 116 | else: # button is pressed:
|
105 |
| - draw.ellipse((100,20,120,40), outline=255, fill=1) #B button filled |
| 117 | + draw.ellipse((100, 20, 120, 40), outline=255, fill=1) #B button filled |
106 | 118 |
|
107 | 119 | if not button_A.value and not button_B.value and not button_C.value:
|
108 | 120 | catImage = Image.open('happycat_oled_64.ppm').convert('1')
|
|
0 commit comments