-
Notifications
You must be signed in to change notification settings - Fork 0
/
bio_test.py
157 lines (124 loc) · 3.86 KB
/
bio_test.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# This test file is to test the LCD screen and button functionalities.
# run this script to verify that all components work correctly.
# SPDX-FileCopyrightText: 2017 James DeVito for Adafruit Industries
# SPDX-License-Identifier: MIT
# This example is for use on (Linux) computers that are using CPython with
# Adafruit Blinka to support CircuitPython libraries. CircuitPython does
# not support PIL/pillow (python imaging library)!
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from PIL import Image, ImageDraw
import adafruit_ssd1306
from src.sola_board_game.bio import *
import time
import neopixel
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Create the SSD1306 OLED class.
disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)
# Input pins:
button_A = DigitalInOut(board.D5)
button_A.direction = Direction.INPUT
button_A.pull = Pull.UP
button_B = DigitalInOut(board.D6)
button_B.direction = Direction.INPUT
button_B.pull = Pull.UP
button_L = DigitalInOut(board.D27)
button_L.direction = Direction.INPUT
button_L.pull = Pull.UP
button_R = DigitalInOut(board.D23)
button_R.direction = Direction.INPUT
button_R.pull = Pull.UP
button_U = DigitalInOut(board.D17)
button_U.direction = Direction.INPUT
button_U.pull = Pull.UP
button_D = DigitalInOut(board.D22)
button_D.direction = Direction.INPUT
button_D.pull = Pull.UP
button_C = DigitalInOut(board.D4)
button_C.direction = Direction.INPUT
button_C.pull = Pull.UP
# Clear display.
disp.fill(0)
disp.show()
# Create blank image for drawing.
# Make sure to create image with mode '1' for 1-bit color.
# test something
width = disp.width
height = disp.height
# test_plot = FreqPlot(width, height, buffer=16, nb_pts=3)
# test_plot.update_freq_plot()
# disp.image(test_plot.main_img)
# disp.show()
print('width = %d' % width)
print('height = %d' % height)
freq_plot = FreqPlot(w=width, h=height, buffer=16, nb_pts=3)
noise_plot = NoisePlot(w=width, h=height, buffer=16, nb_pts=28)
disp.image(freq_plot.main_img)
disp.show()
led_indices = {
"q3": 0,
"dark": 1,
"q1": 2,
"bright": 3,
"q2": 4,
}
PI_PIN_NEOPIXELS = board.D21
NEOPIXEL_COUNT = 5
pixels = neopixel.NeoPixel(
PI_PIN_NEOPIXELS,
NEOPIXEL_COUNT,
brightness=0.2,
# auto_write=False,
pixel_order=neopixel.GRBW,
)
def light_up_pixel(index, color):
print(f"Lighting up pixel {index} with color {color}.")
pixels[index] = color
pixels.show()
time.sleep(0.1) # Add a delay to see the change
# Map frequency to color for both qubits
# Light up bright and dark states when qubits are in resonance
# Light up dark once the noise profile is near the cost function (also do the mapping)?
while True:
if not button_R.value:
freq_plot.update_marker(1)
if not button_L.value:
freq_plot.update_marker(-1)
if not button_U.value:
freq_plot.update_value(-0.1)
for idx, freq in enumerate(freq_plot.values):
rgb = value_to_rgb(freq)+(0,)
light_up_pixel(idx, rgb)
if not button_D.value:
freq_plot.update_value(0.1)
for idx, freq in enumerate(freq_plot.values):
rgb = value_to_rgb(freq)+(0,)
light_up_pixel(idx, rgb)
if (freq_plot.values[0] == freq_plot.values[1]) and (freq_plot.values[2] == (freq_plot.values[1] + freq_plot.hybridization)):
print('First game done!')
success_img = Image.new('1', (width, height))
success_draw = ImageDraw.Draw(success_img)
success_draw.text((16, 32), 'First game done! :)', fill=1)
disp.image(success_img)
disp.show()
time.sleep(5)
break
else:
print(freq_plot.values, freq_plot.hybridization)
disp.image(freq_plot.main_img)
disp.show()
disp.image(noise_plot.main_img)
disp.show()
while True:
if not button_R.value:
noise_plot.update_marker(1)
if not button_L.value:
noise_plot.update_marker(-1)
if not button_U.value:
noise_plot.update_value(-0.1)
if not button_D.value:
noise_plot.update_value(0.1)
disp.image(noise_plot.main_img)
disp.show()