# https://badge.disobey.fi/projects/instanssi_2019_demo import appglue import easywifi import ugfx import badge import math import time import socket import easydraw import _thread badge.init() ugfx.init() easywifi.enable() ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.home() if pushed else False) class Instanssi(object): def __init__(self, nick, ip, port): self.ip = ip self.port = port self.nick = nick self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.reset() def reset(self): self.packet = [ 1 ] # Speksin versio aina yksi self.packet.append(0) # Aloita tagi osa for char in self.nick: # Muunna nickin merkit ascii koodeiksi self.packet.append(ord(char)) self.packet.append(0) # Lopeta tagi osa def set(self, i, r, g, b): self.packet += [ 1, # Tehosteen tyyppi on yksi eli valo i, # Valon indeksi 0, # Laajennustavu. Aina nolla. r, # Punaisuus g, # Vihreys b, # Sinisyys ] def send(self): bytes = bytearray(self.packet) self.socket.sendto(bytes, (self.ip, self.port)) self.reset() valot = Instanssi("disobey2019","10.0.69.22",9909) VALOMAX = 24 def sinline(t): ugfx.clear() for i in range(1,128,2): a = 3.14/128*(i+t*5) y = int(math.sin(a)*30)+30 ugfx.fill_circle(i, y, 2, 1) ugfx.flush() def sintext(text, t): i = 1 for c in text: a = 3.14/128*(i+t*5) y = int(math.sin(a)*30)+25 ugfx.char(i, y, ord(c), "Robo_Regular22", 1) i = i+6 ugfx.flush() def higher(x,y): if x > y: return x return y def valo_gradient(velapsed): for i in range(VALOMAX): valot.set(i, max(0,i*int(255*math.sin(velapsed/255.0))%255), max(0,i*int(255*math.cos(velapsed/255.0))%255), max(0,i*int(255*math.sin((velapsed-254)/255.0))%255)) valot.send() def led_gradient(t): for i in range(1,7): velapsed = t+i*10 badge.led(i-1, max(0,i*int(255*math.sin(velapsed/255.0))%255), max(0,i*int(255*math.cos(velapsed/255.0))%255), max(0,i*int(255*math.sin((velapsed-254)/255.0))%255)) def demoloop(): elapsed = 1 running = True while running: if(elapsed < 50): ugfx.clear() valo_gradient(elapsed) sintext("Hello Instanssi 2019",elapsed+25) sinline(elapsed) elif(elapsed == 50): easydraw.msg("I haz lights, too", "Instanssi", True) led_gradient(elapsed) elif(elapsed < 300): led_gradient(elapsed) time.sleep(0.01) else: easydraw.msg("Greets: Disobey, Wide Load, Nalleperhe, JML") easydraw.msg("kthxbai, ninnnu") running = False elapsed = elapsed + 1 time.sleep(5) appglue.home() _thread.start_new_thread(demoloop, ())