from machine import Pin, I2C
from i2c_lcd import I2cLcd
import random
import time
clubs = Pin(11, Pin.OUT)
hearts = Pin(12, Pin.OUT)
spades = Pin(2, Pin.OUT)
diamonds = Pin(3, Pin.OUT)
ace = Pin(4, Pin.OUT)
jack = Pin(5, Pin.OUT)
queen = Pin(6, Pin.OUT)
king = Pin(9, Pin.OUT)
scl = Pin(1)
sda = Pin(0)
i2c = I2C(0, sda=sda, scl=scl, freq=400000)
devices = i2c.scan()
idcaddr = devices[0]
lcd = I2cLcd(i2c, idcaddr, 2, 16)
def clear_lights():
clubs.value(0)
hearts.value(0)
spades.value(0)
diamonds.value(0)
ace.value(0)
jack.value(0)
queen.value(0)
king.value(0)
def display(suit, number):
lcd.clear()
lcd.putstr(f"{number} of {suit}")
time.sleep(4)
number_pins = {
1: ace,
11: jack,
12: queen,
13: king,
2: Pin(18, Pin.OUT),
3: Pin(18, Pin.OUT),
4: Pin(18, Pin.OUT),
5: Pin(18, Pin.OUT),
6: Pin(18, Pin.OUT),
7: Pin(18, Pin.OUT),
8: Pin(18, Pin.OUT),
9: Pin(18, Pin.OUT),
10: Pin(18, Pin.OUT)
}
def draw():
suits = ["Hearts","Clubs","Diamonds","Spades"]
'''suits = ["Hearts","Hearts","Hearts","Hearts"]'''
'''suits = ["Hearts","Diamonds","Hearts","Diamonds"]'''
numbers = [11, 13, 10, 7, 9, 4, 5, 2, 1, 8, 6, 12, 3]
'''numbers = [1]'''
suit = random.choice(suits)
number = random.choice(numbers)
clear_lights()
if suit == "Clubs":
clubs.toggle()
elif suit == "Hearts":
hearts.toggle()
elif suit == "Spades":
spades.toggle()
elif suit == "Diamonds":
diamonds.toggle()
if number == 1:
ace.toggle()
display(suit, "Ace")
elif number == 11:
jack.toggle()
display(suit, "Jack")
elif number == 12:
queen.toggle()
display(suit, "Queen")
elif number == 13:
king.toggle()
display(suit, "King")
else:
display(suit, str(number))
return suit, number
def game():
winnings = "POT" #default
cards = [draw() for _ in range(3)]
suits = [card[0] for card in cards]
numbers = [card[1] for card in cards]
#all cards are Aces
if all(num == 1 for num in numbers):
winnings = "JACKPOT"
#all cards are the same color
elif all((suit in ["Hearts", "Diamonds"]) == (suits[0] in ["Hearts", "Diamonds"]) for suit in suits):
winnings = "TREASURE"
#all cards are the same suit
elif len(set(suits)) == 1:
winnings = "CACHE"
lcd.clear()
lcd.putstr(f"Player Earnings: {winnings}")
for i in range(3):
game()
time.sleep(2)