Hi there!
I haven’t got any experience with the Unicorn pHat; in fact, I don’t even own one, so I’m sorry if this is a pretty rough explanation, but I noticed your post was from a while back now and I’ve recently had experience with some string manipulation stuff in Python, so I wondered if I could be of any assistance.
Firstly, your way ahead of me, since I haven’t a clue how to change the colour of a Unicorn pHat, so that bit may be a bit more difficult for me to demonstrate, but I’ll try the psuedo-code bit first and it may give you a hint.
Have you managed to get the text file from your external temperature monitoring Pi to your Unicorn Pi? If so, great! This code should be good enough to get you going. If not; I’m afraid I’m not much help. I’ve heard of lots of wireless ways to transmit stuff between Pis, but I’ve had no experience so far.
Now, of course, presuming you want to use Python;
I’ve created a dummy file called “temp.txt” which includes a list of random temperatures (some being pretty extravagant), with each value separated by a line.
3.10
2.95
10.93
11.95
100.45
999999999.999
Here’s an example with what you can do with that txt file:
import os # Importing the module to read the file.
templist = open(“temp.txt”).read().split() #Opening the file in Python
print(templist) # Printing as a test to see if it has been properly opened (not necessary)
for word in templist: # Loops around every value in the list
print(" ") # Just a spacer to make things look nice :)
print(word) # Print the current temperature
if float(word) > 5:
print(“HOT”) # If the temperature is above 5, say it is hot.
elif float(word) <=5:
print(“COLD”) # If the temperature is below or equal to 5, say it is cold.
else:
print(“Error”) # This should be an impossibility, but just in case. You never know when Q may change the laws of physics ;)
Of course, where in this program I am printing either “HOT” or “COLD” you would change it to make the Unicorn pHat show the correct colour.
Now this code runs through the entire list, but I’d presume you’d want it to check the last temperature on the list, instead of all of them;
import os # Importing the module to read the file.
import time # Importing the module to check every hour.
sec = time.time()
def getlast():
templist = open(“temp.txt”).read().split() #Opening the file in Python
last = templist[-1] # Getting the last value in the list
def hotornot(last): # Making a function to check for the temperature, pretty self explanatory
if last > 5:
print(“HOT”)
elif last <= 5:
print(“COLD”)
else:
print(“Q! What have you done!?”)
continue_ = True # Acts as a stopper gauge
while continue_ == True: # While forever:
sec1 = time.time() - sec # Set sec1 as being the time elapsed since the loop began
sec1 = int(sec1) # And make it an integer so we can easily use it
if sec1 == 3600: # If the seconds elapsed are 1 hour
temp = getlast() # Take a new last value from the temp file
light = hotornot(temp) # Find whether it is hot or not
sec = time.time() # Update the time to a new elapsed time
Tada!
I hope that helped. Believe me, I’m a novice. It may not have been helpful at all really, but, oh well!
I wish you luck!
-RaspberryPicardBox