Hi,
I would like to make a "little computer" just for coding in security...
I use upython on a Giga board... It seems that it could works, but I presume problems with the eval of a while loop... I will try with just a "try" before the "while" and an "except KeyboardInterrupt" to leave, but I'm not sure...
My code:
from machine import I2C, Pin, SPI
from ST77352 import TFT
from seriffont import seriffont
import uasyncio
###buttons
b1 = Pin('PE4', Pin.IN, Pin.PULL_UP)
b2 = Pin('PB2', Pin.IN, Pin.PULL_UP)
b3 = Pin('PI14', Pin.IN, Pin.PULL_UP)
b4 = Pin('PJ5', Pin.IN, Pin.PULL_UP)
b5 = Pin('PJ3', Pin.IN, Pin.PULL_UP)
###Lcd display on spi1 ##ScreenSize = (240, 240)
spi = SPI(1, baudrate=20000000)
tft=TFT(spi,Pin('PG9'),Pin('PE5'),Pin('PG7'))
tft.initr()
tft.rotation(1)
###local and global references
name_session= "gg@GiGa1"
texto = ""
v = 1
response = 1
async def display_lcd(texto):
texto = str(texto)
tft.fill(tft.WHITE)
tft.text((5, 30), name_session,tft.BLACK, seriffont, 5, nowrap=True)
tft.text((15, 80), texto,tft.BLACK, seriffont, 3, nowrap=True)
async def check_keyboard():
global texto, v
if b1.value() == 0:##to test a print
print('b1 is pressed')
texto = "print('It works!')"
if b2.value() == 0:###to test an assignment
print('b2 is pressed')
texto = texto + "v=2"
if b3.value() == 0:##to test calcul
print('b3 is pressed')
texto = texto + "v+2"
if b4.value() == 0:##del key
print('b4 is pressed')
try:
texto = str(texto)
texto = texto[:-1]
texto = int(texto)
except:
pass
if b5.value() == 0:##enter key
print('b5 is pressed')
event = uasyncio.Event()
uasyncio.create_task(enter(event))
event.set()
async def enter(event):
global response, texto
for i in texto:
if i == "=":
pl_egal = texto.index(i)
response = 0
if response == 1:
#texto = str(texto)
com = eval(texto)
texto = com
if response == 0:
champs1 = texto[0:pl_egal]
pl_egal += 1
champs2 = texto[pl_egal:]
try:
champs2 = int(champs2)
except:
pass
locals()[champs1] = champs2
response = 1
texto = ""
await event.wait()
event.clear()
async def main():
while 1:
uasyncio.create_task(display_lcd(texto))
uasyncio .create_task(check_keyboard())
await uasyncio.sleep_ms(500)
uasyncio.run(main())
If somoene has an advice...
Thanks.