Thanks for the reply Robert! I know the formula for converting between Celsius and Fahrenheit, I just don’t know where in my code to put that formula to make it display in Fahrenheit instead of Celsius. It displays in Celsius by default.
I figured it would be something like x = (x * 9/5) + 32
But I’m not sure what x is, nor where to put it in the code.
Anyway, as to that, and as to tweeting frequency, here’s the code:
import twitter
import time
import grovepi
import math
Connections
sound_sensor = 0 # port A0
light_sensor = 1 # port A1
temperature_sensor = 2 # port D2
led = 3 # port D3
intro_str = “DI Lab’s”
Connect to Twitter
api = twitter.Api(
consumer_key=‘YourKey’,
consumer_secret=‘YourKey’,
access_token_key=‘YourKey’,
access_token_secret=‘YourKey’
)
grovepi.pinMode(led,“OUTPUT”)
grovepi.analogWrite(led,255) #turn led to max to show readiness
while True:
# Error handling in case of problems communicating with the GrovePi
try:
# Get value from light sensor
light_intensity = grovepi.analogRead(light_sensor)
# Give PWM output to LED
grovepi.analogWrite(led,light_intensity/4)
# Get sound level
sound_level = grovepi.analogRead(sound_sensor)
time.sleep(0.5)
# Get value from temperature sensor
[t,h]=[0,0]
[t,h] = grovepi.dht(temperature_sensor,0)
# Post a tweet
out_str ="%s Temp: %d C, Humidity: %d, Light: %d, Sound: %d" %(intro_str,t,h,light_intensity/10,sound_level)
print (out_str)
api.PostUpdate(out_str)
except IOError:
print("Error")
except KeyboardInterrupt:
exit()
except Exception as e:
print("Duplicate Tweet or Twitter Refusal: {}".format(e))
time.sleep(60)