The situation is that I have a sensor that gives of numbers from the distance on 0cm to 700cm every 2 seconds.
Is it possible to execute a code that reads the last five printed numbers and if they are all above 400cm for it to print something?
def read_sensor(data={}):
value = get_next_value()
data["sum"] = (data.get("sum",0)+(value>400))*(value>400)
return data["sum"]
list(iter(read_sensor,5))
print "OK I got 5 values all over 400"
is one possible way ... I guess ... your co workers might hate you ...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.