Could someone please help to debug my code. I am new in Python programming and I wanted to make my robot scan the ‘barcode’ and at the same time count the ‘inventory boxes’ on the left.I tried doing it in Python Project using a function but my variable ‘inventory’ doesn’t increase the value whenever the distance sensor reads < 30cm. In the end, the display always shows ‘None’. Here is my Python Project link: https://www.robotmesh.com/studio/60a7162ad2cf776482d02749
I tried an alternative way in a Blockly Project to learn using a thread. However, the problem still persist. My variable on thread2 doesn’t count up. Here is my Blockly Project link: https://www.robotmesh.com/studio/60aafe5dd07e4038a62aaf82
I have no problem in scanning my ‘barcode line segments’, my only problem is to count the boxes.
# call detectLines function for 4 times. Store the letter to scannedLetters list for every iteration.
for i in range(5):
scannedLetter[i] = detectLines()
vexiq.lcd_write('Inventory = ' + str(inventory), 3)
You zero out inventory every time detectLines() is called. As a result, it’s 0 when you try to print it. If you want to hold on to the contents of that variable to use later, don’t set it to 0.