import LCD import time from machine import Pin import random # Craps # Roll two dice and display it on the LCD # Shuffle a deck of cards, draw a 5-card poker hand # Display your poker hand Buzzer = Pin(13, Pin.OUT) B0 = Pin(15,Pin.IN,Pin.PULL_UP) B1 = Pin(14,Pin.IN,Pin.PULL_UP) def Beep(): Buzzer.value(1) time.sleep(0.02) Buzzer.value(0) Orange = LCD.RGB(250,200,50) Navy = LCD.RGB(0,0,50) Red = LCD.RGB(250,0,0) White = LCD.RGB(250,250,250) Black = LCD.RGB(0,0,0) Grey = LCD.RGB(150,150,150) Pink = LCD.RGB(250,100,100) LCD.Init() LCD.Clear(Navy) LCD.Box(5,5,475,315,Pink) LCD.Text2('Dice and Playing Cards Demo',10,10,Orange, Navy) LCD.Text('Press Button 15 to continue', 50, 290, Grey, Navy) # Dice Games while(1): d1 = random.randrange(1,6) d2 = random.randrange(1,6) LCD.Dice(d1, 50, 50, Red, White) LCD.Dice(d2, 125, 50, Red, White) LCD.Text('Sum = ',50, 110, White, Navy) LCD.Number(d1+d2, 2, 0, 100, 110, White, Navy) # Card Games Hand = [0,0,0,0,0] Value = [0,0,0,0,0] Suit = [0,0,0,0,0] Y = LCD.Shuffle() for i in range(0,5): Hand[i] = Y[i] Value[i] = Hand[i] % 13 Suit[i] = int(Hand[i] / 13) LCD.Card(Value[i], Suit[i], 50+i*50, 150) LCD.Text('Poker Hand',50,220,White,Navy) while(B0.value() == 0): pass while(B0.value() == 1): pass