Beispiel #1
0
ugfx.orientation(270)
# Title
ugfx.set_default_font(ugfx.FONT_TITLE)
ugfx.Label(0, ugfx.height() - info_height * 2, ugfx.width(), info_height, "TiLDA Mk4", justification=ugfx.Label.CENTER)
# info
ugfx.Label(0, ugfx.height() - info_height, ugfx.width(), info_height, "Press MENU", justification=ugfx.Label.CENTER)

ugfx.set_default_font(ugfx.FONT_SMALL)
status = ugfx.Label(0, ugfx.height() - info_height * 2 - status_height, ugfx.width(), status_height, "", justification=ugfx.Label.CENTER)

# update loop
while True:
    text = "";
    value_wifi_strength = wifi_strength()
    value_battery = battery()
    if value_wifi_strength:
        text += "Wi-Fi: %s%%, " % int(value_wifi_strength)
    if value_battery:
        text += "Battery: %s%%" % int(value_battery)
    status.text(text)
    if Buttons.is_pressed(Buttons.BTN_Star):
        if torch_on:
            torch_on = False
            torch.off()
            neo.display([0,0])
        else:
            torch_on = True
            torch.on()
            neo.display([0xffffff,0xffffff])
    sleep_or_exit(0.5)
Beispiel #2
0
class Air_Quality_Display():
    
    def setup_screen(self):
        """ Set up the screen and the labels that display
            values on it. 
        """
        ugfx.init()
        width=ugfx.width()
        height=ugfx.height()
        ugfx.clear(ugfx.html_color(0x800080))
        style = ugfx.Style()
        style.set_enabled([ugfx.WHITE, ugfx.html_color(0x800080), ugfx.html_color(0x800080), ugfx.html_color(0x800080)])
        style.set_background(ugfx.html_color(0x800080))
        ugfx.set_default_style(style)
        ugfx.orientation(90)
        ugfx.set_default_font(ugfx.FONT_TITLE)
        ugfx.Label(0, 0, width, 60,"Air Quality", justification=ugfx.Label.CENTER)
        label_height=45
        self.ppm10_label = ugfx.Label(0, label_height, width, label_height,"PPM 10: starting", justification=ugfx.Label.CENTER)
        self.ppm25_label = ugfx.Label(0, label_height*2, width, label_height,"PPM 2.5: starting", justification=ugfx.Label.CENTER)

        self.temp_label = ugfx.Label(0, label_height*3, width, label_height,"Temp: starting", justification=ugfx.Label.CENTER)
        self.humid_label = ugfx.Label(0, label_height*4, width, label_height,"Humid: starting", justification=ugfx.Label.CENTER)
        self.error_label = ugfx.Label(0, label_height*5, width, label_height,"", justification=ugfx.Label.CENTER)
        self.message_label = ugfx.Label(0, label_height*6, width, label_height,"", justification=ugfx.Label.CENTER)
        self.error_count = 0
        self.error_message = ""
        self.neopix = Neopix()
        self.p10_decode = ((100,0x00ff00),(250,0xffff00),(350,0xff8000),(430,0xff0000),(-1,0xcc6600))
        self.p25_decode = ((60, 0x00ff00),(91, 0xffff00), (121,0xff8000),(251,0xff0000),(-1,0xcc6600))

    def get_reading_color(self, value, decode):
        for item in decode:
            if item[0] < 0:
                # reached the upper limit - return
                return item[1]
            if value < item[0]:
                return item[1]
    
    def new_readings(self,ppm10_value, ppm25_value):
        """ Called by the sensor to deliver new values to the screen.
            Will also trigger the reading of the temperature and humidity
            values.
        """
        self.ppm10_label.text("PPM 10: "+str(ppm10_value))
        self.ppm25_label.text("PPM 2.5: "+str(ppm25_value))
        temp = Sensors.get_hdc_temperature()
        temp_string = "Temp: {0:2.1f}".format(temp)
        self.temp_label.text(temp_string)
        humid = Sensors.get_hdc_humidity()
        humid_string = "Humidity: {0:2.1f}".format(humid)
        self.humid_label.text(humid_string)
        # Calculate some colours
        self.neopix.display((self.get_reading_color(ppm25_value, self.p25_decode),self.get_reading_color(ppm10_value, self.p10_decode)))

    def error(self, error_message):
        """ Called by the sensor to deliver an error message. 
        Args:
            error_message: error message string
        """
        self.error_count = self.error_count + 1
        self.error_label.text( "Errors: " +str(self.error_count))
        self.message_label.text(str(error_message))
Beispiel #3
0
    b = Buttons.is_pressed(Buttons.BTN_B)
    if not a and not b:
        ugfx.poll()
        continue

    if b:
        duration = duration + 5
        if duration > 60:
            duration = 5
        ugfx.clear()
        instructions(duration)
        continue

    ugfx.clear()

    np.display([0, 0])
    np.display([0x000099, 0x000099])
    devs = sim800.btscan(duration * 1000)
    np.display([0x00, 0x00])

    if len(devs) == 0:
        ugfx.Label(0, 0, 240, 25, "No devices found")
        np.display([0x110000, 0x110000])
        sleep(1)
        np.display([0, 0])
    else:
        if type(devs[0]) == int:
            devs = [devs]

        y = 0
        for dev in devs[:20]:
import os, tilda
from machine import Neopix

n=Neopix()
n.display([0,0,0])
n.display([0,0,0])

print("EMF: boot.py")
os.sync()
root = os.listdir()

def app(a):
    if (a in root) and ("main.py" in os.listdir(a)):
        return a + "/main.py"

def file(file, remove):
    try:
        a = None
        with open(file, 'r') as f:
            a = f.read().strip()
        if remove:
            os.remove(file)
        return app(a)
    except Exception as e:
        print("Not found: %s" % file)

def any_home():
    h = [a for a in root if a.startswith("home")]
    return h[0] if len(h) else False

if "no_boot" in root:
Beispiel #5
0
                    ugfx.width(),
                    status_height,
                    "",
                    justification=ugfx.Label.CENTER)

from tilda import Sensors
from machine import Neopix
n = Neopix()
# update loop
while True:
    text = ""
    value_wifi_strength = wifi_strength()
    value_battery = battery()
    lux = Sensors.get_lux()
    if lux < 1000:
        n.display([0xffffff, 0xffffff])
    elif lux < 2000:
        n.display([0xff00ff, 0xff00ff])
    elif lux < 3000:
        n.display([0x0000ff, 0x0000ff])
    elif lux < 4000:
        n.display([0x00ffff, 0x00ffff])
    elif lux < 5000:
        n.display([0x00ff00, 0x00ff00])
    elif lux < 6000:
        n.display([0xffff00, 0xffff00])
    elif lux < 7000:
        n.display([0xffa500, 0xffa500])
    elif lux < 8000:
        n.display([0xff0000, 0xff0000])
    else:
Beispiel #6
0
from tilda import Buttons

n = Neopix()

mapping = {0: 0x000001, 1: 0x000100, 2: 0x010000}

exit = False


def breakout(x):
    global exit
    exit = True


Buttons.enable_interrupt(Buttons.BTN_Menu,
                         breakout,
                         on_press=True,
                         on_release=False)

while True:
    store = [0, 0]
    incs = [random.randint(0, 2) for _ in range(2)]
    for i in range(0xff):
        store[0] += mapping[incs[0]]
        store[1] += mapping[incs[1]]
        n.display(store)
    if exit:
        break

restart_to_default()
Beispiel #7
0
    playMusic(9500)
    blankScreen()


#############
#############
#############
boot()

enableLights = False
enableScroll = True
while True:
    # Toggle lights
    if buttons.is_triggered(Buttons.BTN_B):
        enableLights = not enableLights
        neopix.display([0, 0])  # Lights off

    # Play music
    elif buttons.is_triggered(Buttons.BTN_A):
        neopix.display([0, 0])  # Lights off
        drawTutorial()
        drawLogo()
        playMusic()

    # Toggle scroll
    elif buttons.is_triggered(Buttons.JOY_Center):
        enableScroll = not enableScroll
        if not enableScroll:
            blankScreen()
            drawLogo()
Beispiel #8
0
Buttons.enable_interrupt(Buttons.BTN_8,
                         cbButton8,
                         on_press=True,
                         on_release=False)

Buttons.enable_interrupt(Buttons.BTN_9,
                         cbButton9,
                         on_press=True,
                         on_release=False)

vip = True
aaa = False

while True:
    if vip_inv:
        vip_inv = False
    else:
        vip_inv = True
    if vip:
        show_vip(vip_inv)
    if strobe:
        if aaa:
            n.display([0xFFA500, 0xFFA500])
            aaa = False
        else:
            n.display([0x000000, 0x000000])
            aaa = True
    else:
        time.sleep(0.1)
Beispiel #9
0
        changed = True
    elif Buttons.is_pressed(Buttons.JOY_Left) and (i > 0):
        i -= 1
        changed = True

    if Buttons.is_pressed(Buttons.JOY_Down) and (j < (maxHeight - 1)):
        j += 1
        changed = True
    elif Buttons.is_pressed(Buttons.JOY_Up) and (j > 0):
        j -= 1
        changed = True

    if changed:
        (r, g, b) = getColour(i / ugfx.width(), j / ugfx.height())
        colour = (int(255 * r) << 16) + (int(255 * g) << 8) + int(255 * b)
        n.display([colour, colour])

        for xx in range((oldI - 1) if (oldI > 0) else 0,
                        1 + ((oldI + 1) if (oldI < (ugfx.width() - 2)) else
                             (ugfx.width() - 1))):
            intensity = xx / ugfx.width()
            for yy in range((oldJ - 1) if (oldJ > 0) else 0,
                            1 + ((oldJ + 1) if (oldJ < (maxHeight - 2)) else
                                 (maxHeight - 1))):
                (rr, gg, bb) = getColour(intensity, yy / ugfx.height())
                colour = (int(31 * rr) << 11) + (int(63 * gg) << 5) + int(
                    31 * bb)
                ugfx.area(xx, yy, 1, 1, colour)

        ugfx.area((i - 1) if i > 0 else 0, (j - 1) if j > 0 else 0, 3 if
                  (i > 0 and i < (ugfx.width() - 1)) else 2, 3 if
Beispiel #10
0
def setup_audio():
    with open('robotnik/robotnik.amr', 'rb') as wavefile:
        print("Writing audio")
        print(sim800.fsrm('C:\\ROBOTNIK.AMR'))
        print(
            sim800.fswrite('C:\\ROBOTNIK.AMR', wavefile.read(), truncate=True))
        print("Saved audio")


ugfx.orientation(90)
ugfx.display_image(0, 0, "robotnik/start.png")
setup_audio()
while 1:
    if playback_start + 15000 < utime.ticks_ms() and sim800.command(
            'AT+CMEDPLAY?')[1][-1] == '0':
        leds.display([0, 0])
        if playback_start + 300000 < utime.ticks_ms():
            playback_start = utime.ticks_ms()
            last_update = playback_start + 1200
            print(sim800.command('AT+CMEDPLAY=1,C:\\REC\\2.AMR,0,100'))
            CURRENT = (YELLOW, RED)
            ugfx.orientation(90)
            try:
                ugfx.clear(db)
                col_i = 0
                cols = [ugfx.RED, ugfx.GREEN]
                for x in range(9):
                    for y in range(11):
                        col_i += 1
                        if col_i % 2:
                            ugfx.area(x * 30, y * 30, 30, 30, lb)