raspberry pi2 - Trouble lighting and extinguishing an LED based on the contents of a variable in Python 2 -
i'm working on weather station draws environment canada data toronto. if wind speed , wind chill results exceeds or falls below numbers, want light leds on breadboard.
the wind speed warning works correctly using following code:
if ((cityobject.get_quantity(wind)) > windmax: gpio.output(13,gpio.high) else: gpio.output(13,gpio.low)
the wind chill warning proving more complex. environment canada returns "none" when there no discernible wind chill. but, eventually, return negative integer instead. following code lights wind chill warning led when, really, should off:
chillzero = "none" if (cityobject.get_quantity(chill)) == chillzero: gpio.output(11,gpio.low) if (cityobject.get_quantity(chill)) < chillmax: gpio.output(11,gpio.high) else: gpio.output(11,gpio.low)
at time of writing, following returns none
print cityobject.get_quantity(chill)
any idea why code causing led stay illuminated? want come on when wind chill below -15c
.
i'm assuming you're confusing string "none"
, type none
.
print cityobject.get_quantity(chill)
print type representation of none
why you'll see none printed.
instead of:
if (cityobject.get_quantity(chill)) == chillzero:
try just:
if cityobject.get_quantity(chill) not none:
also there appears redunant calls, try this:
if (cityobject.get_quantity(chill)) < chillmax: print "windchill: %s" % cityobject.get_quantity(chill) gpio.output(11, gpio.high) else: # greater or equal chillmax, or return none gpio.output(11, gpio.low)
Comments
Post a Comment