def main():

    zoom = 15
    tft = m5stack.Display()

    tft.text(10, 10, "> Reading settings.\n")
    with open("/flash/settings.json") as fp:
        settings = json.loads(fp.read())

    tft.text(10, tft.LASTY, "> Connecting to wifi.\n")
    wifi = Wifi(settings["username"], settings["password"])

    tft.text(10, tft.LASTY, "> Scanning networks.\n")
    networks = wifi.scan()

    tft.text(10, tft.LASTY, "> Locating current position.\n")
    geolocation = Geolocation(settings["api_key"], networks)
    coordinates = geolocation.coordinates()

    tft.text(10, tft.LASTY, "> Downloading the map.\n")
    map = Map(coordinates)
    map.save("/flash/map.jpg")

    tft.image(0, 0, "/flash/map.jpg")

    button_a = DigitalInput(Pin(m5stack.BUTTON_A_PIN, Pin.IN),
                            callback=lambda pin: zoom_in_handler(map, tft))

    button_c = DigitalInput(Pin(m5stack.BUTTON_C_PIN, Pin.IN),
                            callback=lambda pin: zoom_out_handler(map, tft))
Exemple #2
0
from ili934x import ILI9341, color565
from machine import Pin, SPI
from input import DigitalInput
import m5stack

button_a = DigitalInput(
    Pin(m5stack.BUTTON_A_PIN, Pin.IN, Pin.PULL_DOWN),
    callback=lambda pin: display.print("Button A pressed."))

button_b = DigitalInput(
    Pin(m5stack.BUTTON_B_PIN, Pin.IN, Pin.PULL_DOWN),
    callback=lambda pin: display.print("Button B pressed."))

button_c = DigitalInput(
    Pin(m5stack.BUTTON_C_PIN, Pin.IN, Pin.PULL_DOWN),
    callback=lambda pin: display.print("Button C pressed."))

power = Pin(m5stack.TFT_LED_PIN, Pin.OUT)
power.value(1)

spi = SPI(-1,
          baudrate=1200000,
          miso=Pin(m5stack.TFT_MISO_PIN),
          mosi=Pin(m5stack.TFT_MOSI_PIN),
          sck=Pin(m5stack.TFT_CLK_PIN))

display = ILI9341(spi,
                  cs=Pin(m5stack.TFT_CS_PIN),
                  dc=Pin(m5stack.TFT_DC_PIN),
                  rst=Pin(m5stack.TFT_RST_PIN))
 def __init__(self, callback=None, trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING):
     pin = Pin(BUTTON_C_PIN, Pin.IN)
     DigitalInput.__init__(self, pin, callback=callback, trigger=trigger)