from time import sleep_ms from machine import Pin, I2C from gt911 import GT911 import LCD Beeper = Pin(13, Pin.OUT) Beeper.value(0) # Touch Screen Initialization rst_pin = Pin(10, Pin.OUT) irq_pin = Pin(11) sda_pin = Pin(8) scl_pin = Pin(9) touch = GT911( I2C(0, scl=scl_pin, sda=sda_pin, freq=100_000), rst_pin, irq_pin ) touch.init(touch_points=1, refresh_rate=50) # LCD Display initialization Black = LCD.RGB(0,0,0) Red = LCD.RGB(100,0,0) Green = LCD.RGB(0,100,0) Blue = LCD.RGB(0,0,100) White = LCD.RGB(100,100,100) LCD.Init() LCD.Clear(Black) LCD.Title('Poker.py', White, Black) Deck = LCD.Shuffle() Hand = [0]*5; Value = [0]*5 Suit = [0]*5 for i in range(0,5): Hand[i] = Deck[i] Value[i] = (Hand[i] % 13) + 1 Suit[i] = int(Hand[i] / 13) + 1 LCD.Card(Value[i], Suit[i], 50+i*75, 50) LCD.Text2('Deal', 100, 200, White, Black) LCD.Text2('Draw', 300, 200, White, Black) Draw = [0]*5 ptr = 5; while(1): num_points, points_data = touch.read_points() if(num_points > 0): tx = points_data[0][0] ty = points_data[0][1] card = round( (tx-50) / 75) card = max(0, min(4, card)) if(ty < 150): Draw[card] = 1 - Draw[card] #Draw if( (tx > 250)*(tx < 350)*(ty > 200)*(ty < 250) ): for i in range(0,5): if(Draw[i] == 1): Hand[i] = Deck[ptr] ptr = ptr + 1 Draw[i] = 0 Beeper.value(1) sleep_ms(10) Beeper.value(0) # Deal if( (tx > 50)*(tx < 150)*(ty > 200)*(ty < 250) ): Deck = LCD.Shuffle() for i in range(0,5): Hand[i] = Deck[i]; ptr = 5 Draw = [0]*5 for i in range(0,2): Beeper.value(1) sleep_ms(10) Beeper.value(0) sleep_ms(100) print(tx, ty, card, ptr) for i in range(0,5): Value[i] = (Hand[i] % 13) + 1 Suit[i] = int(Hand[i] / 13) + 1 LCD.Card(Value[i], Suit[i], 50+i*75, 50) if(Draw[i] == 1): LCD.Text2('*', 60+i*75, 130, Green, Black) else: LCD.Text2('*', 60+i*75, 130, Black, Black) while(num_points > 0): num_points, points_data = touch.read_points()