Example #1
0
def draw_screen():
    loc_data = get_data("https://freegeoip.app/json/")
    lat = str(loc_data["latitude"])
    lon = str(loc_data["longitude"])
    city = loc_data["city"]
    country = loc_data["country_name"]
    iss_data = get_data("http://api.open-notify.org/iss-pass.json?lat=" + lat + "&lon=" + lon)
    risetime = iss_data['response'][0]['risetime']
    datetime = iss_data['request']['datetime']
    countdown = datetime
    LED(LED.GREEN).off()
    while countdown < risetime:
        ugfx.clear(ugfx.BLACK)
        ugfx.text(5, 5, "When does the ISS next pass?", ugfx.WHITE)
        ugfx.line(5, 20, ugfx.width(), 20, ugfx.GREY)
        ugfx.text(5, 35, "Location: " + city + ", " + country, ugfx.WHITE)
        ugfx.text(5, 50, "Latitude: " + lat, ugfx.WHITE)
        ugfx.text(5, 65, "Longitude: " + lon, ugfx.WHITE)
        ugfx.text(5, 80, "Rise time: " + str(get_time(risetime)), ugfx.WHITE)
        ugfx.text(5, 95, "Duration: " + str(get_seconds(iss_data['response'][0]['duration'])), ugfx.WHITE)
        countdown +=1
        ugfx.text(5, 110, "Countdown: " + str(get_wait(risetime, countdown)), ugfx.WHITE)
        utime.sleep(1)
    else:
        LED(LED.GREEN).on()
        LED(LED.RED).on()
        utime.sleep(1)
        LED(LED.GREEN).off()
        LED(LED.RED).off()
        draw_screen()
Example #2
0
def get_beer():
    global bar
    LED(LED.RED).on()
    try:
        bar_json = http.get("https://bar.emf.camp/location/Bar.json"
                            ).raise_for_status().content
        bar = ujson.loads(bar_json)
    except:
        print('oh poop')
    LED(LED.RED).off()
    draw_screen()
Example #3
0
def doLights():
    # LED Flash
    if _randrange(1, 10) <= 5:
        LED(LED.RED).on()
    else:
        LED(LED.RED).off()

    if _randrange(1, 10) <= 5:
        LED(LED.GREEN).on()
    else:
        LED(LED.GREEN).off()

    # NEO Pixels
    colorNum1 = _randrange(0, ledColourCount - 1)
    colorNum2 = _randrange(0, ledColourCount - 1)
    neopix.display([ledColours[colorNum1], ledColours[colorNum2]])
Example #4
0
def get_trains(station_code='LBG'):
    print('trains/api: Getting trains for {}'.format(station_code))
    station_data = None

    LED(LED.RED).on()  # Red for total get_trains
    try:
        station_json = http.get(
            API_URL.format(station_code)).raise_for_status().content
        LED(LED.GREEN).on()  # Green for parsing
        station_data = ujson.loads(station_json)
    except Exception as e:
        print('Error:')
        print(e)

    LED(LED.RED).off()
    LED(LED.GREEN).off()
    return station_data
Example #5
0
def ledChange():
    print("led change!")
    RedLEDNum = random.randint(0, 1)
    GreenLEDNum = random.randint(0, 1)

    if RedLEDNum == 0:
        LED(LED.RED).on()
    else:
        LED(LED.RED).off()

    if GreenLEDNum == 0:
        LED(LED.GREEN).on()
    else:
        LED(LED.GREEN).off()

    colourNum1 = colourList[random.randint(0, 510)]
    colourNum2 = colourList[random.randint(0, 510)]
    n.display([colourNum1, colourNum2])
Example #6
0
def get_strip():
    global strip

    LED(LED.RED).on()
    try:
        strip_json = http.get("https://xkcd.com/info.0.json").raise_for_status().content
        strip = ujson.loads(strip_json)
    except: 
        print('couldn't fetch strip json')
    LED(LED.RED).off()

    LED(LED.GREEN).on()
    try:
        strip_img = http.get(strip['img']).raise_for_status().content
        ugfx.display_image(0,0,bytearray(strip_img))
    except: 
        print('couldn't fetch strip image')
    LED(LED.GREEN).off()
Example #7
0
def get_data(api_url):
    
    try:
        data_json = http.get(api_url).raise_for_status().content
        data = ujson.loads(data_json)
        LED(LED.GREEN).on()
    except: 
        print('Something has gone wrong')

    return data
from tilda import LED
from time import sleep

LED(LED.RED).on()
LED(LED.GREEN).off()

while True:
    LED(LED.RED).toggle()
    LED(LED.GREEN).toggle()
    sleep(0.1)