from machine import ADC from time import sleep from random import randrange import LCD Fortune = [ 'It is certain ', 'Reply hazy, try again ', 'Dont count on it ', 'It is decidedly so ', 'Ask again later ', 'My reply is no ', 'Without a doubt ', 'Better not tell you now ', 'My sources say no ', 'Yes definitely ', 'Cannot predict now ', 'Outlook not so good ', 'You may rely on it ', 'Concentrate and ask again', 'Very doubtful ', 'As I see it, yes ', 'Most likely ', 'Outlook good ', 'Yes ', 'Signs point to yes '] a2d2 = ADC(2) Navy = LCD.RGB(0,0,5) White = LCD.RGB(200,200,200) LCD.Init() LCD.Clear(Navy) LCD.Title('Magic 8-Ball', White, Navy) k = 200 / 65535 while(1): # start with the sensor facing up z1 = a2d2.read_u16() Az = k * (z1 - 13843) -3.6 LCD.Text2(' ', 5, 100, White, Navy) if(Az < 1): LCD.Text('Place upright then ask a question ', 100, 50, White, Navy) while(Az < 1): z1 = a2d2.read_u16() Az = k * (z1 - 13843) -3.6 sleep(0.01) LCD.Text('Ask a question then shake three times', 100, 50, White, Navy) N = 0 while(N < 3): Az = 0 while(Az < 5): z1 = a2d2.read_u16() Az = k * (z1 - 13843) -3.6 sleep(0.01) while(Az > -5): z1 = a2d2.read_u16() Az = k * (z1 - 13843) -3.6 sleep(0.01) N += 1 LCD.Text('Turn over to find your answer ', 100, 50, White, Navy) sleep(0.5) Az = 0 while(Az > -5): z1 = a2d2.read_u16() Az = k * (z1 - 13843) -3.6 #print('Your Fortune') N = randrange(20) LCD.Text2(Fortune[N], 5, 100, White, Navy) sleep(2)