from microbit import * import music #----------- KOMPLETAN DEMO BW - SA I2C KOMUNIKACIJOM I BITMAPOM 01.09.2020 sleep(2000) 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 teksts(): # DEMO text ispis("CLS") ispis("1.Hello!;20;0;G") # draw text, x,y, graphics mode (G) - in buffer ispis("2.Hello!;22;8;G") ispis("3.Hello!;24;16;G") ispis("4.Hello!;26;24;G") ispis("5.Hello!;28;32;G") ispis("6.Hello!;30;40;G") ispis("DIS") # display buffer on screen sleep(500) for n in range(84): ispis("SCC;L;2;2;R") # scroll horisontal, LEFT, x,y, rotate screen ispis("SCC;R;3;3;R") # scroll horisontal, RIGHT, x,y, rotate screen sleep(10) sleep(500) for n in range(12): ispis("SCU;R") # scroll UP, rotate screen sleep(300) for n in range(12): ispis("SCD;R") # scroll DOWN, rotate screen sleep(300) sleep(1000) def tekst(): ispis("CLS") ispis("Hello!;20;0;G") # draw text to buffer (G) ispis("DIS") # display buffer on screen ispis("Hello!;22;8;G") ispis("DIS") # display buffer on screen ispis("Hello!;24;16;G") ispis("DIS") # display buffer on screen ispis("Hello!;26;24;G") ispis("DIS") # display buffer on screen ispis("Hello!;28;32;G") ispis("DIS") ispis("Hello!;30;40;G") ispis("DIS") sleep(2000) ispis("CLS") ispis("Hi!;3;1;2") # draw text to screen sleep(2000) ispis("CLS") ispis("CON;40;C") # contrast set to 40 ispis("Hi!;2;1;3") for n in range(40,65,2): ispis("CON;"+str(n)+";C") # set contrast sleep(100) sleep(1000) ispis("CLS") for n in range(1,3,1): ispis("Hi!;2;1;"+str(n)+";C") # draw text to screen - black (C) sleep(500) ispis("Hi!;2;1;"+str(n)+";B") # draw text to screen - white (B) ( erase text on screen ) sleep(50) ispis("Hi!;2;1;3;C") sleep(1000) ispis("CLS") for n in range(10): if n < 10: ispis(str(n)+";5;1;3;C") # draw text (number) sleep(200) ispis(str(n)+";5;1;3;B") # erase text else: ispis(str(n)+";3;1;3;C") sleep(200) ispis(str(n)+";3;1;3;B") ispis("CLS") ispis("START;2;1;2;C") sleep(1000) def meni(): # start menu ispis("CLS") ispis("DEMO TEXT;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(): tekst() id = 0 if button_b.was_pressed(): teksts() id = 0