Пример #1
0
def withPhat():
    # global prevLevel #can remove next
    while True:
        tijd = time.localtime()  #create a struct_time object
        if tijd[4] in interval_List:  #and check if the number of minutes is in the interval_List
            currTime = time.asctime()[
                11:16]  #if yes create an hour and minute string using .asctime
            currTime = currTime + ':00'  #add the zeros

            getNap()  #get and set current nap_list
            # walk through it searching match with currTime nap_list[i][1]
            # for i in nap_list: doesn't work in this case (because I need the index number?)
            for i in range(len(nap_list)):
                if nap_list[i][1] == currTime:
                    currLevel = int(nap_list[i][5])  #currLevel is an int
                    prevLevel = int(nap_list[i - 1][5])
                    diffLevel = currLevel - prevLevel
                    #print(str('%+d' % diffLevel)) #+d formatting for pos and neg numbers
                    print(currTime, str(currLevel), str('%+d' % diffLevel))
                    #prevLevel = currLevel
                    # Microdot Phat code follows
                    display = str(currLevel) + str('%+d' % diffLevel)
                    microdotphat.clear()
                    microdotphat.write_string(display, kerning=False)
                    microdotphat.show()
            time.sleep(65)  # waits a bit more than a minute
        time.sleep(5)
def show_temperature(delay):
    clear()
    temp = weather.temperature()
    write_string("%.2f" % temp + "c", kerning=False)
    show()
    time.sleep(delay)
    g.labels(host=host).set(temp)
def update_display(cost, trend):
    ''' Function to update the display '''
    if (len(cost) > 1) and (len(cost) < 7):
        # Start with a clear buffer
        md.clear()

        # Right justify string
        char_offset = 6 - len(cost)
        md.write_string(cost, offset_x=(8 * char_offset), kerning=False)

        # Add trend - character set here: https://github.com/pimoroni/microdot-phat/blob/master/library/microdotphat/font.py
        if trend == 'UP':
            # Solid upwards triangle
            md.write_char(chr(9650), offset_x=0)
        elif trend == 'up':
            # Open upwards triangle
            md.write_char(chr(9651), offset_x=0)
        elif trend == 'down':
            # Open downwards triangle
            md.write_char(chr(9661), offset_x=0)
        elif trend == 'DOWN':
            # Solid downwards triangle
            md.write_char(chr(9660), offset_x=0)

        # Write the buffer to the display
        md.show()
Пример #4
0
def write_to_display(message, brightness=1):
    if i2c_present:
        clear()
        set_brightness(brightness)
        write_string(message.rjust(6), kerning=False)
        show()
    else:
        print(message)
def read_temp_LM75(SensorID):
    clear()
    temp_raw = sensor.getTemp()
    if temp_raw > 128:
        measurement = temp_raw - 256
    else:
        measurement = temp_raw
    return measurement
Пример #6
0
def microdot():
    clear()
    write_string( "%.1f" % temperature + "C", kerning=False)
    show()
    time.sleep(5)
    clear()
    write_string( "%.0f" % humidity + "% RH", kerning=False)
    show()
    time.sleep(5)
def mostra_data():
    tempo_data = 0
    while tempo_data < tempo_switch:
        clear()
        t = datetime.datetime.now()
        if t.second % 2 == 0:
            set_decimal(3, 1)
        else:
            set_decimal(3, 0)
        write_string(t.strftime('%a %d').upper(), kerning=False)
        show()
        time.sleep(0.05)
        tempo_data = tempo_data + 1
Пример #8
0
def main():

    key = 'cc8047a5-a693-417a-9721-c6213690acbb'
    ely = '324249'
    cambridge = '350731'
    #fcDataType = wxfcs or wxobs
    weatherType = {
    'NA': 'Huh?', '1': 'Sunny', '2': 'Cloudy', '3': 'Cloudy', '4': 'Huh?', '5': 'Misty', '6': 'Foggy', '7': 'Cloudy',
    '8':"O'cast", '9': 'L-Shwr', '10': 'L-Shwr', '11': 'Drizzl', '12': 'L-Rain', '13': 'H-Shwr', '14': 'H-Shwr',
    '15': 'H-Rain', '16': 'L-Sleet', '17': 'L-Sleet', '18': 'Sleet', '19': 'L-Hail', '20': 'L-Hail', '21': 'Hail!!',
    '22': 'L-Snow', '23': 'L-Snow', '24': 'L-Snow', '25': 'Snow', '26': 'Snow', '27': 'H-Snow', '28': 'Stormy',
    '29': 'Stormy', '30': 'Stormy'
	}
    
    while True:
        response = urllib2.urlopen('http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/' + ely + '?res=3hourly&key=' + key)
        fcData = response.read()
        fcDataStr = fcData.decode('utf-8')
        fcDataDict = json.loads(fcDataStr)
        dataDate = (fcDataDict['SiteRep']['DV']['dataDate'])
        fcDate = (fcDataDict['SiteRep']['DV']['Location']['Period'][1]['value'])
        fcTime = (fcDataDict['SiteRep']['DV']['Location']['Period'][1]['Rep'][3]['$'])
        fcTemp = (fcDataDict['SiteRep']['DV']['Location']['Period'][1]['Rep'][3]['T'])
        fcPp = (fcDataDict['SiteRep']['DV']['Location']['Period'][1]['Rep'][3]['Pp'])
        fcWeather = (fcDataDict['SiteRep']['DV']['Location']['Period'][1]['Rep'][3]['W'])
        
        print '\n'
        print '**** New Data ****'
        print 'Forecast Date = ' + fcDate
        print 'Forecast time = ' + fcTime
        print 'Temp DegC = ' + fcTemp
        print 'Rain % = '+ fcPp
        print 'Weather type = ' + fcWeather
        weather = weatherType[fcWeather]
        print weather
        
        msg = 'Forecast: 9AM tomorrow'
        #write_string(msg, offset_x = 7, kerning = False)      
        write_string(weather, offset_y = 0, kerning = False)
        write_string('T: ' + fcTemp, offset_y = 7, kerning = False)
        write_string('R% ' + fcPp, offset_y = 14, kerning = False)
   
        for updateInterval in range(900):
            show()
            time.sleep(4)       
            for pixelRow in range(7):
                scroll_vertical()
                show()
                time.sleep(0.03)
        clear()
Пример #9
0
def show_time(duration=10):
    repeat_in = 0.05
    repeat_times = int(duration / repeat_in)

    for counter in range(0, repeat_times):
        microdotphat.clear()
        t = datetime.datetime.now()
        if t.second % 2 == 0:
            microdotphat.set_decimal(3, 1)
        else:
            microdotphat.set_decimal(3, 0)
        microdotphat.write_string(t.strftime(' %H%M'), kerning=False)
        microdotphat.show()
        time.sleep(repeat_in)
Пример #10
0
def microdot():
    clear()
    write_string("%.1f" % temperature + "C", kerning=False)
    show()
    time.sleep(5)
    # Uncomment to display pressure if needed
    #clear()
    #write_string( "%.0f" % pressure + "hPa", kerning=False)
    #show()
    #time.sleep(5)
    clear()
    write_string("%.0f" % humidity + "% RH", kerning=False)
    show()
    time.sleep(5)
Пример #11
0
def clock():
    while True:
        clockEndTime = time.time() + showClock
        while time.time() < clockEndTime:
            clear()
            t = datetime.datetime.now()
            if t.second % 2 == 0:
                set_decimal(2, 1)
                set_decimal(4, 1)
            else:
                set_decimal(2, 0)
                set_decimal(4, 0)
            write_string(t.strftime('%H%M%S'), kerning=False)
            show()
            time.sleep(0.05)
Пример #12
0
def mostra_saldo():
    tempo_saldo = 0
    saldo_euro = leggehttp()
    while tempo_saldo < tempo_switch:
        clear()
        char_euro()
        t = datetime.datetime.now()
        if t.second % 2 == 0:
            set_decimal(3, 1)
        else:
            set_decimal(3, 0)
        write_string(saldo_euro, offset_x=8, kerning=False)
        show()
        time.sleep(0.05)
        tempo_saldo = tempo_saldo + 1
def drawMatrix(matrix):

    gamma = 1.5
    MDP_HEIGHT = 6

    mdp.clear()

    for x in range(len(matrix)):
        buf_x = x + ((x / 5) * 3)

        for y in xrange(7):
            if matrix[x] > pow(gamma, y):
                mdp.set_pixel(buf_x, MDP_HEIGHT - y, 1)
            else:
                break

    mdp.show()
Пример #14
0
def init():
    import pigpio
    global pi
    global getAdjustment
    global i2c_handle

    pi = pigpio.pi()
    getAdjustment = getAdjustmentReal

    microdotphat.clear()

    i2c_handle = pi.i2c_open(1, 0x28)

    pi.set_mode(SWITCH_GPIO_PIN, pigpio.INPUT)
    pi.set_pull_up_down(SWITCH_GPIO_PIN, pigpio.PUD_UP)
    pi.set_glitch_filter(SWITCH_GPIO_PIN,
                         200000)  # Report change only after 200ms steady
Пример #15
0
    def render_string(s,
                      scroll_x=8,
                      scroll_y=0,
                      scroll_sleep=1,
                      kerning_flag=False):
        # init view
        clear()

        # render string
        write_string(s, kerning=kerning_flag)
        show()
        time.sleep(scroll_sleep)

        # render to end
        for i in range(len(s)):
            # scroll -> render
            scroll(scroll_x, scroll_y)
            show()
            time.sleep(scroll_sleep)
Пример #16
0
def getNap():
    global nap_list
    try:
        with requests.Session() as s:
            download = s.get(csv_url)
            decoded_content = download.content.decode('utf-8')
            cr = csv.reader(decoded_content.splitlines(), delimiter=';')
            nap_list = list(cr)
            return nap_list
    except IndexError:
        microdotphat.clear()
        microdotphat.write_string('IndEr1', kerning=False)
        microdotphat.show()
        print('IndexError 1: getNAP')
    except ConnectionError:
        microdotphat.clear()
        microdotphat.write_string('ConErr', kerning=False)
        microdotphat.show()
        print('ConnectionError: getNAP')
Пример #17
0
def print_string_fade(text):
    start = time.time()
    speed = 3
    shown = True

    b = 0
    while shown:
        b = (math.sin((time.time() - start) * speed) + 1) / 2
        microdotphat.set_brightness(b)

        if b < 0.002 and shown:
            microdotphat.clear()
            microdotphat.write_string(text, kerning=False)

            microdotphat.show()
            shown = False

        if b > 0.998:
            shown = True

        time.sleep(0.01)
Пример #18
0
def mostra_orologio():
    #verifico se c'e' connessione ad Internet
    connesso_internet = 0
    connesso_internet = connessione()

    tempo_orologio = 0
    while tempo_orologio < tempo_switch:
        clear()
        t = datetime.datetime.now()
        if t.second % 2 == 0:
            set_decimal(3, 1)
        else:
            set_decimal(3, 0)
        # se manca la connessione ad internet, durante la visualizzazione dell'ora viene anteposto un asterisco
        if (connesso_internet == 0):
            write_string(t.strftime(' %H%M'), kerning=False)
        else:
            write_string(t.strftime('*%H%M'), kerning=False)

        show()
        time.sleep(0.05)
        tempo_orologio = tempo_orologio + 1
async def initLogger():
    print("Start logger...")

    await asyncio.sleep(1) 
    
    while True:    
        if len(cache) == 0:
            await asyncio.sleep(2) 
            
        else:
            try:
                for key in cache:
                    print(cache[key])
                    
                    # Write to PHAT
                    clear()
                    write_string(cache[key], kerning=False)
                    show()
                    await asyncio.sleep(2) 
                
            except Exception:
               pass
Пример #20
0
def withPhat():
    while True:
        tijd = time.localtime()  #create a struct_time object
        if tijd[4] in interval_List:  #and check if the number of minutes is in the interval_List
            currTime = time.asctime()[
                11:16]  #if yes create an hour and minute string using .asctime
            currTime = currTime + ':00'  #add the zeros

            getNap()  #get and set current nap_list
            # walk through it searching match with currTime nap_list[i][1]
            # for i in nap_list: doesn't work in this case (because I need the index number?)
            for i in range(len(nap_list)):
                try:
                    if nap_list[i][1] == currTime:
                        currLevel = int(nap_list[i][5])  #currLevel is an int
                        prevLevel = int(nap_list[i - 1][5])
                        diffLevel = currLevel - prevLevel
                        #print(str('%+d' % diffLevel)) #+d formatting for pos and neg numbers
                        print(currTime, str(currLevel), str('%+d' % diffLevel))
                        # Microdot Phat code follows
                        display = str(currLevel) + str('%+d' % diffLevel)
                        microdotphat.clear()
                        microdotphat.write_string(display, kerning=False)
                        microdotphat.show()
                        lookAhead(nap_list,
                                  currTime)  #send nap_list to lookAhead
                except IndexError:
                    microdotphat.clear()
                    microdotphat.write_string('IndEr2', kerning=False)
                    microdotphat.show()
                    logging.info('IndexError 2 in withPhat')
                    print('IndexError 2 in withPhat')
                    time.sleep(65)  #not sure how long to wait
                    continue  #does this work here?

        time.sleep(65)  # waits a bit more than a minute to escape if = true
    time.sleep(5)
Пример #21
0
import time
from microdotphat import write_string, scroll, clear, show

clear()
write_string('Forecast, SNOWCATS!   ')

while True:
    scroll()
    show()
    time.sleep(0.01)
Пример #22
0
#!/usr/bin/env python

import datetime
import time

from microdotphat import write_string, set_decimal, clear, show

print("""Thermal

Displays the temperature measured from thermal zone 0, using
/sys/class/thermal/thermal_zone0/temp

Press Ctrl+C to exit.
""")

delay = 1

while True:
    clear()
    path="/sys/class/thermal/thermal_zone0/temp"
    f = open(path, "r")
    temp_raw = int(f.read().strip())
    temp = float(temp_raw / 1000.0)
    write_string( "%.2f" % temp + "c", kerning=False)
    show()
    time.sleep(delay)
Пример #23
0
import microdotphat as dot
import Adafruit_DHT
import time

sensor = Adafruit_DHT.DHT11
pin = 23

dot.clear()
dot.set_rotate180(False)
dot.write_string('Hello_', kerning=False)
dot.show()
time.sleep(3)
dot.write_string(' P1X ', kerning=False)
dot.show()
time.sleep(1)

while True:
    dot.write_string('>LOAD<', kerning=False)
    dot.show()
    hum, temp = Adafruit_DHT.read_retry(sensor, pin)
    repeat = 8
    while repeat > 0:
        if hum is not None and temp is not None:
            dot.write_string('C {0:0.1f}'.format(temp), kerning=False)
            dot.show()
            time.sleep(2)

            dot.write_string('% {0:0.1f}'.format(hum), kerning=False)
            dot.show()
            time.sleep(2)
        else:
Пример #24
0
 def write(self, msg):
     dot.clear()
     dot.write_string(msg, kerning=False)
     dot.show()
     return True
Пример #25
0
 def loading(self):
     dot.clear()
     dot.fill(1)
     dot.show()
Пример #26
0
 def __init__(self):
     dot.clear()
     dot.set_rotate180(True)
     dot.fill(1)
     dot.show()
Пример #27
0
 def clear():
     clear()
     show()
Пример #28
0
 def clear():
     clear()
Пример #29
0
def setup(CONFIG):
    getBuilds(CONFIG)
    microdotphat.clear()
    microdotphat.write_string(CONFIG['phatText'], kerning=False)
Пример #30
0
def reset():
    microdotphat.clear()
    microdotphat.show()