from microbit import * import music import random #----------- DEMO BW - SA I2C KOMUNIKACIJOM I BITMAPOM 01.09.2020 sleep(3000) def ispis(tekst): dd = len(tekst) if dd < 31: salji(tekst) else: salji(tekst[0:30]+"+") salji(tekst[30:dd]) def salji(tekst): duz = len(tekst) buf = bytearray(duz) for n in range(0, duz): bb = ord(tekst[n:n+1]) buf[n] = bb try: i2c.write(0x11, buf) sleep(duz*4) except OSError: print("er: salji") def grafikas(): # GRAPHICS DEMO - EYES ispis("CLS") # clear screen ispis("LIN;32;40;52;40;C") # draw line ispis("LIN;32;41;52;41;C") for n in range(1): ispis("CIR;20;20;15;C;C") # draw circle - black (C) ispis("CIR;62;20;15;C;C") sleep(500) for m in range(11,15,1): ispis("CIR;20;20;"+str(m)+";B") # draw circle - white (B) ispis("CIR;62;20;"+str(m)+";B") sleep(1000) for m in range(2): for n in range(5): ispis("SCC;R;0;5") # horisontal scroll to RIGHT from row 0 - 5 ( all screen ) sleep(10) # to slow scroll for n in range(10): ispis("SCC;L;0;5") # horisontal scroll to LEFT from row 0 - 5 ( all screen ) sleep(10) for n in range(5): ispis("SCC;R;0;5") # horisontal scroll to RIGHT from row 0 - 5 ( all screen ) sleep(10) for m in range(2): for n in range(5): ispis("SBU;1") # graphics scroll UP for 1 bit sleep(10) # to slow scroll for n in range(10): ispis("SBD;1") # graphics scroll DOWN for 1 bit sleep(10) for n in range(5): ispis("SBU;1") # graphics scroll UP for 1 bit sleep(10) ispis("CLS") m = 0 for n in range(84): m = m + 1 if m == 4: m = 0 y = random.randrange(48) ispis("CIR;80;"+str(y)+";2;C;F") # draw circle ispis("SCC;L;0;5") # horisontal scroll to LEFT from row 0 - 5 ( all screen ) ispis("CLS") xp = 78 yp = random.randrange(48) m = 0 for n in range(84): ispis("SCC;L;0;5") m = m + 1 if m == 5: m = 0 y = random.randrange(48) ispis("LIN;78;"+str(yp)+";83;"+str(y)+";C") # draw line yp = y sleep(50) ispis("CLS") def grafika(): # GRAPHICS DEMO - STANDARD FUNCTIONS ispis("CLS") ispis("LIN;32;40;52;40;C") # draw line ispis("LIN;32;41;52;41;C") for n in range(2): ispis("CIR;20;20;15;C;C") # draw circle ispis("CIR;62;20;15;C;C") sleep(500) for m in range(11,15,1): ispis("CIR;20;20;"+str(m)+";B") ispis("CIR;62;20;"+str(m)+";B") sleep(1000) ispis("CLS") for n in range(5,40,2): ispis("LIN;10;"+str(n)+";70;"+str(n)+";C") for n in range(5,40,2): ispis("LIN;10;"+str(n)+";70;"+str(n)+";B") for n in range(5,24,2): ispis("CIR;42;24;"+str(n)+";C") for n in range(5,24,2): ispis("CIR;42;24;"+str(n)+";B;B") ispis("CIR;42;24;24;C;C") for m in range(5,24,2): ispis("CIR;42;24;"+str(m)+";B") sleep(50) ispis("CLS") for n in range(0,24,2): py = 24 - n px = 42 - n m = n * 2 ispis("REC;"+str(px)+";"+str(py)+";"+str(m)+";"+str(m)+";C") # draw rectange for n in range(0,24,2): py = 24 - n px = 42 - n m = n * 2 ispis("REC;"+str(px)+";"+str(py)+";"+str(m)+";"+str(m)+";B") ispis("REC;"+str(px)+";"+str(py)+";"+str(m)+";"+str(m)+";C;B") for n in range(0,24,2): py = 24 - n px = 42 - n m = n * 2 ispis("REC;"+str(px)+";"+str(py)+";"+str(m)+";"+str(m)+";B;B") ispis("CLS") for n in range(30): x = random.randrange(84) y = random.randrange(48) ispis("PIX;"+str(x)+";"+str(y)+";C") # draw pixels sleep(100) def meni(): # start menu ispis("CLS") ispis("DEMO GRAPHICS;0;0") ispis("A-standard;0;2") ispis("B-scroll;0;3") ispis("LIN;0;12;83;12;C") ispis("LIN;0;36;83;36;C") poz = 1 ispis("CLS") id = 0 while True: if id == 0: meni() id = 1 if button_a.was_pressed(): grafika() id = 0 if button_b.was_pressed(): grafikas() id = 0