from machine import Pin, SPI import time import utime import LCD # Lunar Lander game # Shows off the analog inputs (thrust) and the graphics routines in LCD a2d0 = machine.ADC(0) a2d1 = machine.ADC(1) B0 = Pin(15, Pin.IN, Pin.PULL_UP) B1 = Pin(14, Pin.IN, Pin.PULL_UP) led = Pin(17, Pin.OUT) led2 = Pin(16, Pin.OUT) a2d0 = machine.ADC(0) a2d1 = machine.ADC(1) DataX = []; DataY = []; # Main Routine led.value(1) LCD.Init() Navy = LCD.RGB(0, 0, 50) White = LCD.RGB(250,250,250) flag =0 while(flag == 0): if(B1.value() == 0): flag = 1 led2.value(1) LCD.Clear(Navy) led2.value(0) LCD.Text2('Lunar Lander Game',125, 10, LCD.RGB(120, 250, 60), Navy) LCD.Text('rev 03/10/24',200, 40, LCD.RGB(80, 200, 40), Navy) LCD.Line(0,300,480,300,0xFFFF) LCD.Line(240,305,240,295,0xFFFF) x = 10.0 y = 250.0 dx = 0.0 dy = 0.0 dt = 0.1 x0 = a2d0.read_u16()/2000 y0 = a2d1.read_u16()/2000 by = 320 bx = 320 while( y > 0 ): fx = a2d0.read_u16()/2000 - x0 fy = a2d1.read_u16()/2000 - y0 ddx = fx ddy = fy - 2.35 LCD.Lander(x,300-y,Navy) x = x + dx*dt y = y + dy*dt dx = dx + ddx*dt dy = dy + ddy*dt LCD.Lander(x,300-y,White) LCD.Box(400,300,420,bx,Navy) LCD.Box(422,300,442,by,Navy) by = int(300-fy*10) bx = int(300-fx*10) LCD.Box(400,300,420,bx,White) LCD.Box(422,300,442,by,White) time.sleep(0.01) LCD.Text2('Impact Velocity = ',10,100,LCD.RGB(250,250,60), Navy) LCD.Number2(abs(dy), 6, 3, 300, 100, LCD.RGB(250,250,60), Navy) LCD.Text2('Error(x) = ',10,132,LCD.RGB(250,60,250), Navy) LCD.Number2(abs(x-240), 6, 3, 300, 132, LCD.RGB(250,60,250), Navy) LCD.Text('Press Button 0 to Continue', 130, 170, LCD.RGB(200,200,200), Navy) while( (B0.value() == 1) & (B1.value() == 1)): if(B1.value() == 0): flag = 1 print('Game Over')