import LCD import time from machine import Pin import random # Play a game of Roulette on the LCD # Button 15 spins the wheel # Button 14 results in number 7 Buzzer = Pin(13, Pin.OUT) LED17 = Pin(17, Pin.OUT) LED16 = Pin(16, 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,0) Navy = LCD.RGB(0,0,30) White = LCD.RGB(250,250,250) Grey = LCD.RGB(150,150,150) Black = 0 Pink = LCD.RGB(250,100,100) Yellow = LCD.RGB(250,250,0) X0 = time.ticks_us() LCD.Init() LCD.Clear(Navy) X1 = time.ticks_us() print('LCD Clear: ',X1-X0,'us') X0 = time.ticks_us() LCD.Box(10,10,470,310,Pink) X1 = time.ticks_us() print('LCD Draw Box: ',X1-X0,'us') X0 = time.ticks_us() LCD.Text2('Roulette Wheel',100,30,Yellow, Navy) X1 = time.ticks_us() print('LCD Text2: ',X1-X0,'us') X0 = time.ticks_us() LCD.Text('Press Button to Start', 100, 70, Grey, Navy) X1 = time.ticks_us() print('LCD Clear: ',X1-X0,'us') LCD.Text2('Winning Number = ',100,150, Orange, Navy) Ball = 1 X0 = time.ticks_us() LCD.Bar_Out(1, 100, 100) X1 = time.ticks_us() print('Display Time = ',X1-X0,'us') for i in range(0,16): LCD.Number((16-i), 1, 0, 95+15*i, 120, Grey, Navy) while (True): while(B0.value() and B1.value()): pass if(B1.value() == 1): X = random.randrange(1,16) print('Fair Wheel',(X+Ball+48)%16+1) else: X = (16+6-Ball) print('Rigged Wheel',(X+Ball+48)%16+1) LED17.value(1) for i in range(0,X+48): Ball = (Ball + 1)%16 LCD.Bar_Out(Ball+1, 100, 100) Beep() LED16.toggle() if(i < X+47): time.sleep(1 / (X+48-i)) LED17.value(0) LCD.Number2(Ball+1, 2, 0, 370, 150, Orange, Navy)