-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscreen.py
More file actions
67 lines (55 loc) · 1.98 KB
/
Copy pathscreen.py
File metadata and controls
67 lines (55 loc) · 1.98 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from generate_trials import trials, generate_stim, regular_poly, GPIO, pygame, np
import pendulum
import csv
import sys
import random
def main():
# GPIO setup
short_pin = 17
long_pin = 27
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(short_pin, GPIO.OUT)
GPIO.setup(long_pin, GPIO.OUT)
# PyGame setup
pygame.init()
screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
clock = pygame.time.Clock()
pygame.mouse.set_visible(False)
points = regular_poly(8, 400, 240, 170)
# Flags
pos_undecided = True
while True:
if pos_undecided:
pos_a, pos_b = random.sample(points, 2)
pos_undecided = False
short_btn = pygame.draw.circle(screen, (236, 245, 66), pos_a, 50) # yellow
long_btn = pygame.draw.circle(screen, (174, 2, 242), pos_b, 50) # purple
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
raise SystemExit
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
pos = pygame.mouse.get_pos()
if short_btn.collidepoint(pos):
GPIO.output(short_pin, GPIO.HIGH)
screen.fill("black")
pygame.display.flip()
pygame.time.delay(200)
GPIO.output(short_pin, GPIO.LOW)
pos_undecided = True
elif long_btn.collidepoint(pos):
GPIO.output(long_pin, GPIO.HIGH)
screen.fill("black")
pygame.display.flip()
pygame.time.delay(200)
GPIO.output(long_pin, GPIO.LOW)
pos_undecided = True
pygame.display.flip()
clock.tick(60)
if __name__ == "__main__":
try:
main()
finally:
GPIO.cleanup()