Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bitcoin price checker for Pimoroni Four Letter Phat / Raspberry Pi
import time
import string
from random import randint
import random
import fourletterphat as flp
import urllib2
import json
# String of numbers for display to cycle while loading. Can be any letters/numbers. It's random.
numbers = "1234567890"
while True:
# End time - number at end (2) is seconds for loading screen (random numbers) to show
t_end = time.time() + 2
while time.time() < t_end:
flp.clear()
flp.set_digit(0, random.choice(numbers))
flp.set_digit(1, random.choice(numbers))
flp.set_digit(2, random.choice(numbers))
flp.set_digit(3, random.choice(numbers))
flp.show()
# Sleep for 0.05 seconds before choosing more random numbers
time.sleep(0.05)
flp.clear()
data = urllib2.urlopen("https://www.bitstamp.net/api/ticker").read()
dataJSON = json.loads(data)
price = dataJSON["last"]
# Convert full number to XX.Xk
flp.set_digit(0, price[0])
flp.set_digit(1, price[1])
flp.set_digit(2, price[2])
# Display "K" (thousand) as 4th digit
flp.set_digit(3, "K")
# Show decimal
flp.set_decimal(1, True)
flp.show()
# Sleep for 500 seconds, then refresh it all
time.sleep(500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment