-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
executable file
·62 lines (52 loc) · 1.53 KB
/
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
#!/usr/bin/python
import pygame
from pygame.locals import *
import os
from time import sleep
import RPi.GPIO as GPIO
#Setup the GPIOs as outputs - only 4 and 17 are available
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)
#Colours
WHITE = (255,255,255)
vexit = False
os.putenv('SDL_FBDEV', '/dev/fb1')
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
pygame.init()
pygame.mouse.set_visible(False)
lcd = pygame.display.set_mode((320, 240))
lcd.fill((0,0,0))
pygame.display.update()
font_big = pygame.font.Font(None, 50)
touch_buttons = {'Off':(80,60), '20':(240,60), '30':(80,180), '40':(240,180)}
for k,v in touch_buttons.items():
text_surface = font_big.render('%s'%k, True, WHITE)
rect = text_surface.get_rect(center=v)
lcd.blit(text_surface, rect)
pygame.display.update()
while True:
# Scan touchscreen events
for event in pygame.event.get():
if(event.type is MOUSEBUTTONDOWN):
pos = pygame.mouse.get_pos()
print pos
elif(event.type is MOUSEBUTTONUP):
pos = pygame.mouse.get_pos()
print pos
#Find which quarter of the screen we're in
x,y = pos
if y < 120:
if x < 160:
GPIO.output(17, False)
else:
GPIO.output(4, False)
else:
if x < 160:
GPIO.output(17, True)
else:
vexit = True
sleep(0.1)
if vexit:
break