-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (56 loc) · 2.31 KB
/
main.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
import gc
import machine
from machine import Pin, ADC, I2C
from libs import lcd
from tetris import Game
import control
import music
# initialize
machine.freq(240000000)
gc.collect()
# init lcd
spi_sck = Pin(2, Pin.OUT)
spi_tx = Pin(3, Pin.OUT)
lcd_reset = Pin(0, Pin.OUT)
lcd_dc = Pin(1, Pin.OUT)
lcd_width = 240
lcd_height = 240
spi_lcd = machine.SPI(0, baudrate=80000000, phase=1, polarity=1,
sck=spi_sck, mosi=spi_tx)
display = lcd.lcd_config(spi_lcd, width=lcd_width, height=lcd_height,
reset=lcd_reset, dc=lcd_dc, rotation=0)
game = Game(display)
controller = control.Controller()
# set joystick
control.xAxis = ADC(Pin(29))
control.yAxis = ADC(Pin(28))
joystick_controller = \
control.Joystick([control.x_value, False, 0xFFF, 120, game.move_left],
[control.x_value, True, 0xEFFF, 120, game.move_right],
[control.y_value, False, 0xFFF, 120, game.rotate],
[control.y_value, True, 0xEFFF, 120, game.move_down])
controller.set_joystick(joystick_controller)
# set button
control.buttonB = Pin(5, Pin.IN, Pin.PULL_UP) # B
control.buttonA = Pin(6, Pin.IN, Pin.PULL_UP) # A
control.buttonStart = Pin(7, Pin.IN, Pin.PULL_UP)
control.buttonSelect = Pin(8, Pin.IN, Pin.PULL_UP)
button_controller = \
control.Button([control.buttonB, Pin.IRQ_FALLING, 150, game.rotate],
[control.buttonA, Pin.IRQ_FALLING, 150, game.drop],
[control.buttonStart, Pin.IRQ_FALLING, 150, game.start_game],
[control.buttonSelect, Pin.IRQ_FALLING, 150, game.pause_game])
controller.set_button(button_controller)
# set accelerometer
i2c = I2C(1, scl=Pin(11), sda=Pin(10), freq=400000)
accelerometer = control.Accelerometer(i2c)
accelerometer.set_events([accelerometer.accel.getAcceleration_y, (-2, -0.5), 120, game.move_left],
[accelerometer.accel.getAcceleration_y, (0.5, 2), 120, game.move_right],
[accelerometer.accel.getAcceleration_x, (-2, -0.5), 120, game.move_down],
[accelerometer.accel.getAcceleration_x, (0.5, 2), 120, game.rotate])
controller.set_accelerometer(accelerometer)
# set game controller
game.set_controller(controller)
# set theme music
game.set_theme_music(music.theme_music_event)
game.run()