def show_clock():
    str_time = time.strftime("%H%M")

    fourletterphat.clear()
    fourletterphat.print_str(str_time)
    fourletterphat.set_decimal(1, int(time.time() % 2))
    fourletterphat.show()
Beispiel #2
0
def showtime():
    global debug
    global fourchar_flag
    global fourchar_payload

    # old logic actually worked, to a point
    fourchar_flag = False
    str_time = time.strftime("%H%M")
    flp.print_number_str(str_time)
    if int(time.time()) % 2 == 0:
        flp.set_decimal(1, 1)
    else:
        flp.set_decimal(1, 0)
    flp.show()
    time.sleep(0.1)
    # new logic
    #    flp.print_str("    ")
    #    flp.show
    #    float_temp = float(fourchar_payload)
    #    flp.print_float(float_temp, decimal_digits=1, justify_right=True)
    #    flp.show()
    #    time.sleep(2)

    # old logic
    if fourchar_flag == True:
        flp.print_str("    ")
        flp.show
        float_temp = float(fourchar_payload)
        flp.print_float(float_temp, decimal_digits=1, justify_right=True)
        flp.show()
        time.sleep(2)
    def _set_decimal(self, index, state):
        """ set decimal at given index """

        # should be called with _exec_with_lock
        lights_off = self._settings.get("_lights_off")
        if self._brightness > 0 and not lights_off:
            display.set_decimal(index, state)
            display.show()
Beispiel #4
0
def dispTemp():

    #establish location, if city is two words use and underscore between them
    #state use two letter abbreviation
    city = "New_York"
    state = "NY"

    #build the url
    url = "http://api.wunderground.com/api/API_KEY_HERE/conditions/q/" + state + "/" + city + ".json"

    #request our url
    f = urllib.request.urlopen(url)

    #open and read the url
    json_string = f.read()

    #encode the url into strings instead of bytes
    encoding = f.info().get_content_charset('utf-8')

    #parse the encoded data into something we can use JSON with
    parsed_json = json.loads(json_string.decode(encoding))

    #grabbing specific datum with parsed JSON
    temp_f = parsed_json['current_observation']['temp_f']
    strTemp_f = (str)(temp_f)

    #FourLetterPhat wasn't printing decimal so we are removing it
    strippedTemp = strTemp_f.replace(".", "")

    fourletterphat.clear()

    #printing what we grabbed
    fourletterphat.print_str(strippedTemp + "F")

    #setting the decimal at 1 works for double digit temps/looking into how to get to to lineup for single or triple digit temps
    fourletterphat.set_decimal(1, True)
    fourletterphat.show()

    #closing the url
    f.close()
Beispiel #5
0
def on_message(client, userdata, msg):
    """The callback for when a PUBLISH message is received from the server."""
    global g_mqtt_data

    print(msg.topic + " -> " + str(msg.payload.decode('UTF-8')))
    message_data = json.loads(str(msg.payload.decode('UTF-8')))

    g_mqtt_data[msg.topic] = message_data

    # Flash the rightmost decimal to show receipt of a message
    flp.set_decimal(3, True)
    flp.show()
    time.sleep(.5)
    flp.set_decimal(3, False)
    flp.show()
    time.sleep(.25)
    flp.set_decimal(3, True)
    flp.show()
    time.sleep(.5)
    flp.set_decimal(3, False)
    flp.show()
Beispiel #6
0
#!/usr/bin/python

import time
import fourletterphat as flp

while True:
    flp.print_str(time.strftime("%I%M"))
    amp = time.strftime("%p")
    if amp == "AM":
        flp.set_decimal(1, 0)
    else:
        flp.set_decimal(1, 1)
    flp.show()
    time.sleep(0.1)
Beispiel #7
0
def time_string():
	return time.strftime("%H%M")







while True:
	flp.clear()
	try:
		if (time.strftime("%S") == "00"):
			ctr = 1
			str_time = full_string()

			flp.scroll_print(str_time,0.5)
		else:

			str_time = time_string()
			flp.print_number_str(str_time)
			flp.set_decimal(1, int(time.time() % 2))
			flp.show()
			time.sleep(0.1)
	except:
		print('Error at{}'.format(full_string))# if exception 1 raised do this



Beispiel #8
0
  data = urllib2.urlopen("https://www.bitstamp.net/api/ticker").read()
  dataJSON = json.loads(data)

  price = dataJSON["last"]
  # Convert full number to XX.Xk




  print(price)
 # Decides where to place decimal, or if to use at all
  if float(price) > 99 and float(price) < 1000:
    flp.set_digit(1, price[1])
    flp.set_digit(2, price[2])
    flp.set_digit(3, price[3])
    flp.set_decimal(2, True)
  elif float(price) > 999 and float(price) <10000:
    # If you prefer 9999 instead of 9,9K
    flp.set_digit(0, price[0])
    flp.set_digit(1, price[1])
    flp.set_digit(2, price[2])
    flp.set_digit(3, price[3])

    # If you prefer 9,9K instead of 9999
    #flp.set_digit(1, price[0])
    #flp.set_digit(2, price[1])
    #flp.set_decimal(1, True)
    #flp.set_digit(3, "K")

  elif float(price) > 9999 and float(price) < 100000:
    flp.set_digit(0, price[0])
Beispiel #9
0
#!/usr/bin/env python

import time
import fourletterphat
from subprocess import Popen, PIPE

print("""
Four Letter pHAT: cpu-temp.py

This example will display your Pi's CPU
temperature in degrees celsius.

Press Ctrl+C to exit.
""")

while True:
    # Get temp forom vcgencmd in the format: "temp=XY.Z'C"
    # and reduce to the format "XYZC" for display
    temp = Popen(["vcgencmd", "measure_temp"], stdout=PIPE)
    temp = temp.stdout.read().decode('utf-8')
    temp = temp[5:].replace(".", "").replace("'", "").strip()

    fourletterphat.clear()
    fourletterphat.print_str(temp)
    fourletterphat.set_decimal(1, 1)
    fourletterphat.show()

    time.sleep(1)
Beispiel #10
0
            display_message(['AQI'], [aqi, last_1hr_aqi])

        if (wind_gust >= 10):
            display_message(['GUST'], [wind_gust])

        if (rain_rate > 0):
            display_message(['RAIN', 'RATE'], [rain_rate])

        display_message(['TEMP'], [temp])

        display_message(['1H'], [temp_change])

        display_message([], [temp])

        display_message(['24H'], [temp_change_24h])

        display_message([], [temp])

    # Give the main display a rest at night and show a blinky pattern
    else:
        flp.clear()
        for i in range(4):
            flp.set_decimal(i, True)
            flp.show()
            time.sleep(.1)
            flp.set_decimal(i, False)
            flp.show()
        time.sleep(8)  # Total = 10s of sleep

    time.sleep(2)
Beispiel #11
0
#!/usr/bin/env python

import time
import fourletterphat

print("""
Four Letter pHAT: clock.py

This example will display a simple HH/MM clock,
with a blinking decimal point to indicate seconds.

Press Ctrl+C to exit.
""")

while True:
    fourletterphat.clear()

    str_time = time.strftime("%H%M")

    # Display the time
    fourletterphat.print_number_str(str_time)

    # Blink the middle decimal point
    # int(time.time() % 2) will alternate 1 0 1 0
    # which we can use to directly set the point
    fourletterphat.set_decimal(1, int(time.time() % 2))

    fourletterphat.show()
    time.sleep(0.1)
Beispiel #12
0
#!/usr/bin/env python

import time
import fourletterphat as flp

test_chars = ["****", "0000"]

while True:
    for char in test_chars:
        flp.clear()
        flp.print_str(char)
        flp.show()
        time.sleep(0.25)
    for i in range(4):
        flp.set_decimal(i, 1)
    flp.show()
    time.sleep(0.25)