0

This is the code:

def check_ultra():
    global arduinoSerialData,y,i
    y=None
    i=None
    while True:
        if arduinoSerialData.inWaiting() > 1:
            myData = arduinoSerialData.readline()
            myData = str(myData)
            myData = myData.replace("b'", '')
            myData = myData.replace("\\r\\n'", str(0))
            myData = myData.replace("\\r00.000", str(0))
            myData = myData.replace("\\r00.000", str(0))
            if myData.find("b"):
                myData_b = myData.replace("a", str(0))
                if float(myData_b) < 15 and float(myData_b) > 1:
                    y=1
                    return y
            if myData.find("a"):
                myData_a = myData.replace("b", str(0))
                if float(myData_a) < 15 and float(myData_a) > 1:
                    y=2
                    i=1
                    return i
                    return y
            else:
                y=0
                return y


m1=0
count=1
y=0
i=0
y == 0
while y==None or y==0:
    i=0
    y=None
    check_ultra()
    while y==2 and i==1:
        y=None
        i=None
        print("Hello")
        break

The problem is with the y==2 loop.For some reason it keeps repeating itself, even if y=None.Anyone know how to solve this, I've been on it the whole day.Thanks!

strilz
  • 63
  • 7
  • 2
    Your `break` statement is outside any of the `while` loops. – 9769953 Aug 09 '20 at 09:53
  • 1
    I also noticed two `return` statements directly below each other; the second will never be reached. – 9769953 Aug 09 '20 at 09:53
  • The indentation of your last `while` is off by one space; please double check, as this should result in an `IndentationError`. – 9769953 Aug 09 '20 at 09:53
  • You return values, but you then ignore them in the calling part. How about using `return y, i` in the various return points of `check_ultra`, and then near the bottom, use `y, i = check_ultra()`. You can then also remove `y` and `i` from the `global` declaration. – 9769953 Aug 09 '20 at 09:56
  • Sorry , but i dont really get where to add that.Could you give an example maybe?Thanks! – strilz Aug 09 '20 at 10:31

1 Answers1

0

Indentation error. Put break inside the loop.

For example:

for val in "string":
    if val == "i":
        break
    print(val)