[python] ValueError: invalid literal for int () with base 10

This seems like readings is sometimes an empty string and obviously an error crops up. You can add an extra check to your while loop before the int(readings) command like:

while readings != 0 | readings != '':
    global count
    readings = int(readings)